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
501
votes
21 answers

Why does DEBUG=False setting make my django Static Files Access fail?

Am building an app using Django as my workhorse. All has been well so far - specified db settings, configured static directories, urls, views etc. But trouble started sneaking in the moment I wanted to render my own beautiful and custom 404.html and…
JWL
  • 13,591
  • 7
  • 57
  • 63
498
votes
30 answers

How can I get the full/absolute URL (with domain) in Django?

How can I get the full/absolute URL (e.g. https://example.com/some/path) in Django without the Sites module? That's just silly... I shouldn't need to query my DB to snag the URL! I want to use it with reverse().
mpen
  • 272,448
  • 266
  • 850
  • 1,236
497
votes
13 answers

How to query as GROUP BY in Django?

I query a model: Members.objects.all() And it returns: Eric, Salesman, X-Shop Freddie, Manager, X2-Shop Teddy, Salesman, X2-Shop Sean, Manager, X2-Shop What I want is to know the best Django way to fire a group_by query to my database,…
simplyharsh
  • 35,488
  • 12
  • 65
  • 73
484
votes
12 answers

CORS: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true

I have a setup involving Frontend server (Node.js, domain: localhost:3000) <---> Backend (Django, Ajax, domain: localhost:8000) Browser <-- webapp <-- Node.js (Serve the app) Browser (webapp) --> Ajax --> Django(Serve ajax POST requests) Now, my…
ixaxaar
  • 6,411
  • 3
  • 24
  • 33
480
votes
32 answers

How to convert JSON data into a Python object?

I want to convert JSON data into a Python object. I receive JSON data objects from the Facebook API, which I want to store in my database. My current View in Django (Python) (request.POST contains the JSON): response = request.POST user =…
Sai Krishna
  • 7,647
  • 6
  • 29
  • 40
477
votes
8 answers

How do I do an OR filter in a Django query?

I want to be able to list the items that either a user has added (they are listed as the creator) or the item has been approved. So I basically need to select: item.creator = owner or item.moderated = False How would I do this in Django?…
Mez
  • 24,430
  • 14
  • 71
  • 93
476
votes
12 answers

django order_by query set, ascending and descending

How can I order by descending my query set in django by date? Reserved.objects.all().filter(client=client_id).order_by('check_in') I just want to filter from descending all the Reserved by check_in date.
gadss
  • 21,687
  • 41
  • 104
  • 154
473
votes
10 answers

How to delete a record in Django models?

I want to delete a particular record like: delete from table_name where id = 1; How can I do this in a django model?
user426795
  • 11,073
  • 11
  • 35
  • 35
455
votes
18 answers

Convert Django Model object to dict with all of the fields intact

How does one convert a django Model object to a dict with all of its fields? All ideally includes foreign keys and fields with editable=False. Let me elaborate. Let's say I have a django model like the following: from django.db import…
Zags
  • 37,389
  • 14
  • 105
  • 140
450
votes
4 answers

How can I filter a Django query with a list of values?

I'm sure this is a trivial operation, but I can't figure out how it's done. There's got to be something smarter than this: ids = [1, 3, 6, 7, 9] for id in ids: MyModel.objects.filter(pk=id) I'm looking to get them all in one query with…
ajwood
  • 18,227
  • 15
  • 61
  • 104
448
votes
25 answers

How to see the raw SQL queries Django is running?

Is there a way to show the SQL that Django is running while performing a query?
spence91
  • 77,143
  • 9
  • 27
  • 19
441
votes
10 answers

Where can I find the error logs of nginx, using FastCGI and Django?

I'm using Django with FastCGI + nginx. Where are the logs (errors) stored in this case?
ha22109
  • 8,036
  • 13
  • 44
  • 48
439
votes
17 answers

Can I access constants in settings.py from templates in Django?

I have some stuff in settings.py that I'd like to be able to access from a template, but I can't figure out how to do it. I already tried {{CONSTANT_NAME}} but that doesn't seem to work. Is this possible?
Paul Wicks
  • 62,960
  • 55
  • 119
  • 146
432
votes
16 answers

NumPy array is not JSON serializable

After creating a NumPy array, and saving it as a Django context variable, I receive the following error when loading the webpage: array([ 0, 239, 479, 717, 952, 1192, 1432, 1667], dtype=int64) is not JSON serializable What does this mean?
Karnivaurus
  • 22,823
  • 57
  • 147
  • 247
431
votes
5 answers

Django Model() vs Model.objects.create()

What it the difference between running two commands: foo = FooModel() and bar = BarModel.objects.create() Does the second one immediately create a BarModel in the database, while for FooModel, the save() method has to be called explicitly to add…
0leg
  • 13,464
  • 16
  • 70
  • 94