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
288
votes
11 answers

Dynamically adding a form to a Django formset

I want to dynamically add new forms to a Django formset, so that when the user clicks an "add" button it runs JavaScript that adds a new form (which is part of the formset) to the page.
Brian Tol
  • 4,149
  • 6
  • 24
  • 27
285
votes
32 answers

Django development IDE

I have done a little Django development, but it has all been in a text editor. I was curious what more advanced development tools others are using in their Django development. I am used to using Visual Studio for development and really like the…
Adam Carr
  • 2,986
  • 7
  • 31
  • 38
283
votes
17 answers

Django Server Error: port is already in use

Restarting the Django server displays the following error: this port is already running.... This problem occurs specifically on Ubuntu and not other operating systems. How can I free up the port to restart the server?
Ashish Kumar Saxena
  • 4,400
  • 8
  • 27
  • 48
280
votes
7 answers

Checking for empty queryset in Django

What is the recommended idiom for checking whether a query returned any results? Example: orgs = Organisation.objects.filter(name__iexact = 'Fjuk inc') # If any results # Do this with the results without querying again. # Else, do something…
Niklas
  • 5,736
  • 7
  • 35
  • 42
279
votes
16 answers

Django: Get list of model fields?

I've defined a User class which (ultimately) inherits from models.Model. I want to get a list of all the fields defined for this model. For example, phone_number = CharField(max_length=20). Basically, I want to retrieve anything that inherits from…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
275
votes
6 answers

How to put comments in Django templates?

I would like to comment this with a line: {% if something.property %} ... {% # this is a comment %} {% if something.property %}
...
Alex. S.
  • 143,260
  • 19
  • 55
  • 62
274
votes
24 answers

How to change site title, site header and index title in Django Admin?

How can I change the site title Django site admin, the site header Django administration and the index title Site administration in Django Admin?
samurailawngnome
  • 3,355
  • 3
  • 18
  • 17
274
votes
10 answers

You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application

I am working on Django project with virtualenv and connect it to local postgres database. when i run the project is says, ImportError: No module named psycopg2.extensions then i used this command to install pip install psycopg2 then during the…
Muhammad Taqi
  • 5,356
  • 7
  • 36
  • 61
273
votes
15 answers

Having Django serve downloadable files

I want users on the site to be able to download files whose paths are obscured so they cannot be directly downloaded. For instance, I'd like the URL to be something like this: http://example.com/download/?f=somefile.txt And on the server, I know…
damon
  • 14,485
  • 14
  • 56
  • 75
272
votes
3 answers

How to add multiple objects to ManyToMany relationship at once in Django ?

Based on the Django doc, I should be able to pass multiple objects at once to be added to a manytomany relationship but I get a * TypeError: unhashable type: 'list' when I try to pass a django queryset casted in a list. Passing a Queryset or a…
philgo20
  • 6,337
  • 6
  • 34
  • 43
271
votes
9 answers

How do I filter ForeignKey choices in a Django ModelForm?

Say I have the following in my models.py: class Company(models.Model): name = ... class Rate(models.Model): company = models.ForeignKey(Company) name = ... class Client(models.Model): name = ... company = models.ForeignKey(Company) …
Tom
  • 42,844
  • 35
  • 95
  • 101
271
votes
13 answers

Proper way to handle multiple forms on one page in Django

I have a template page expecting two forms. If I just use one form, things are fine as in this typical example: if request.method == 'POST': form = AuthorForm(request.POST,) if form.is_valid(): form.save() # do…
Adam Nelson
  • 7,932
  • 11
  • 44
  • 64
270
votes
38 answers

Django - makemigrations - No changes detected

I was trying to create migrations within an existing app using the makemigrations command but it outputs "No changes detected". Usually I create new apps using the startapp command but did not use it for this app when I created it. After debugging,…
Dilraj
  • 2,791
  • 2
  • 15
  • 9
269
votes
11 answers

TransactionManagementError "You can't execute queries until the end of the 'atomic' block" while using signals, but only during Unit Testing

I am getting TransactionManagementError when trying to save a Django User model instance and in its post_save signal, I'm saving some models that have the user as the foreign key. The context and error is pretty similar to this question django…
Gaurav Toshniwal
  • 3,552
  • 2
  • 24
  • 23
265
votes
5 answers

Django - what is the difference between render(), render_to_response() and direct_to_template()?

Whats the difference (in language a python/django noob can understand) in a view between render(), render_to_response() and direct_to_template()? e.g. from Nathan Borror's basic apps examples def comment_edit(request, object_id,…
Ryan
  • 23,871
  • 24
  • 86
  • 132