Questions tagged [django]

Django is an open-source server-side web application framework written in Python. It is designed to reduce the effort required to create complex data-driven websites and web applications, with a special focus on less code, no-redundancy and being more explicit than implicit.

PyPI

Django: The Web framework for perfectionists with deadlines

Django is a high-level web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers and maintained by the non-profit Django Software Foundation (DSF). it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.

Django follows the (model-view-controller) architectural pattern. This consists of:

  • an object-relational mapper that mediates between data models
    (Python classes) and a relational database ("Model")

  • a system for processing requests with a web templating system ("View")

  • a regular-expression-based URL dispatcher ("Controller")

The team prefers to think of Django as an "MTV" framework, where 'M' is the model, 'T' is the template and 'V' is view.

In , 'views' describe which data are presented while 'templates' describe how that data is presented.

Resources

Useful books

Tutorials

Newsletters

Podcasts

Popular Third Party Apps

Websites Using Django

See also:

309060 questions
53
votes
9 answers

How do you reload a Django model module using the interactive interpreter via "manage.py shell"?

I know how to reload a regular Python module within a regular Python interpreter session. This question documents how to do that pretty well: How do I unload (reload) a Python module? For some reason, I am having trouble doing that within Django's…
Chad Braun-Duin
  • 2,188
  • 2
  • 19
  • 26
53
votes
7 answers

Performing a getattr() style lookup in a django template

Python's getattr() method is useful when you don't know the name of a certain attribute in advance. This functionality would also come in handy in templates, but I've never figured out a way to do it. Is there a built-in tag or non-built-in tag that…
JJ.
  • 4,974
  • 5
  • 39
  • 48
53
votes
6 answers

Django Selective Dumpdata

Is it possible to selectively filter which records Django's dumpdata management command outputs? I have a few models, each with millions of rows, and I only want to dump records in one model fitting a specific criteria, as well as all foreign-key…
Cerin
  • 60,957
  • 96
  • 316
  • 522
53
votes
31 answers

Command not found: django-admin.py

I am a complete beginner to Python/Django, but I want to dive right in and start experimenting. Thus I was following this guide on installing Python/Django http://devcenter.heroku.com/articles/django. Everything is working fine until the…
Simon
  • 2,263
  • 2
  • 19
  • 26
53
votes
4 answers

In the Django admin site, how do I change the display format of time fields?

I recently added a new model to my site, and I'm using an admin.py file to specify exactly how I want it to appear in the admin site. It works great, but I can't figure out how to get one of my date fields to include seconds in it's display format.…
Trindaz
  • 17,029
  • 21
  • 82
  • 111
53
votes
4 answers

Django admin - inline inlines (or, three model editing at once)

I've got a set of models that look like this: class Page(models.Model): title = models.CharField(max_length=255) class LinkSection(models.Model): page = models.ForeignKey(Page) title = models.CharField(max_length=255) class…
The_OP
  • 667
  • 1
  • 8
  • 11
53
votes
4 answers

Django templates: forloop.first and forloop.last

I have the following code in my template: {% for f in friendslist %} {% if forloop.first %} // display something {% endif %} // display stuff {% if forloop.last %} …
Sammy
  • 557
  • 1
  • 5
  • 6
53
votes
7 answers

Django returns 403 error when sending a POST request

when I'm using following Python code to send a POST request to my Django website I'm getting 403: Forbidden error. url = 'http://www.sub.example.com/' values = { 'var': 'test' } try: data = urllib.urlencode(values, doseq=True) req =…
Djent
  • 2,877
  • 10
  • 41
  • 66
53
votes
9 answers

How to break "for loop" after 1 iteration in Django template

I have this code {% for account in object_list %} {% for field, value in book.get_fields %} {{ field.verbose_name }} {% endfor %} {{ break }} {% endfor %} I want to…
tej.tan
  • 4,067
  • 6
  • 28
  • 29
53
votes
5 answers

Django - Class Based Generic View - "No URL to redirect to"

I'm using the generic CreateView like: #urls.py from django.conf.urls.defaults import * from django.views.generic import CreateView from content.models import myModel urlpatterns = patterns('myApp.views', (r'myCreate/$',…
Pierre de LESPINAY
  • 44,700
  • 57
  • 210
  • 307
53
votes
13 answers

Django Python rest framework, No 'Access-Control-Allow-Origin' header is present on the requested resource in chrome, works in firefox

I have researched and read quite a few Stackoverflow posts on the same issue. None have resolved my issue. My problem is that I am getting the "...No 'Access-Control-Allow-Origin' header is present on the requested resource..." error in my…
53
votes
1 answer

How to perform filtering with a Django JSONField?

I'm using PostgreSQL and this new field from Django 1.9, JSONField. So I got the following data: id|data 1 |[{'animal': 'cat', 'name': 'tom'}, {'animal': 'dog', 'name': 'jerry'}, {'animal': 'dog', 'name': 'garfield'}] I'm trying to figure out how…
ezdookie
  • 1,477
  • 3
  • 15
  • 19
53
votes
3 answers

How can one change the type of a Django model field from CharField to ForeignKey?

I need to change the type of a field in one of my Django models from CharField to ForeignKey. The fields are already populated with data, so I was wondering what is the best or right way to do this. Can I just update the field type and migrate, or…
ChrisM
  • 2,128
  • 1
  • 23
  • 41
53
votes
2 answers

django static annotation

I want to add a static value to the results of a database query using django (so not using 'raw' SQL) For example, if I have an object Car with fields make, model, and color, then I want my results set with extra static value to look something like…
Trindaz
  • 17,029
  • 21
  • 82
  • 111
53
votes
5 answers

How to add a sortable count column to the Django admin of a model with a many-to-one relation?

Suppose I have a Book model containing a foreign key to a Publisher model. How can I display in the Django admin a column with the number of books published by each publisher, in a way that I can use the built-in sorting?
GJ.
  • 5,226
  • 13
  • 59
  • 82