{"canonical_url":"https://engineer.company/glossary/django/","content_markdown":"# Django\n\n## What it is\n\nDjango is a web framework written in Python: a request comes in, the URL\nconfiguration routes it to a function or class called a view, and the view\nreturns a response, usually HTML rendered from a template or JSON. Around that\ncore it ships the parts most database-backed sites need, among them an\nobject-relational mapper, schema migrations, forms, authentication with\npermissions, and an automatically generated admin interface that its own\ndocumentation calls one of its most popular features. The project is written\nwith a capital D, while the package you install and import is the lowercase\n`django`.\n\nIt came out of a newsroom. In fall 2003 Adrian Holovaty and Simon Willison,\ndevelopers at World Online, the web department of a newspaper in Lawrence,\nKansas, moved from PHP to Python for the sites they built on journalism\ndeadlines. While building sites such as Lawrence.com they extracted a generic\nframework from the work, refined it for two years, and in summer 2005 World\nOnline released it as open source. It is named after Django Reinhardt, the jazz\nmanouche guitarist, is pronounced JANG-oh with a silent D, and is distributed\nunder the 3-clause BSD licence.\n\nUnder the A.B numbering, feature releases came roughly every eight months, and\nonly designated long-term support releases received three years of support; 5.2\nLTS is supported until April 2028. Django 6.2, an LTS release due in April 2027,\nis the last one under that policy. From Django 2028 on, feature releases are\nnamed for their year, arrive every January, and each receives the same\nthree-year support period.\n\nThe project's FAQ suggests calling Django an MTV framework, for model, template\nand view: the model defines the data, the view decides which data the user sees,\nand the template decides how it looks. The controller, in that reading, is the\nframework itself, the machinery that sends each request to the right view.\nModels are Python classes, and queries against them are QuerySets, which are\nlazy: a QuerySet can be built, filtered and passed around without touching the\ndatabase, which is queried only when something evaluates it, such as a loop.\nChanges to models become migrations: `makemigrations` packages each change into\na file that the documentation compares to a commit in a version control system\nfor the schema, and `migrate` applies it. Related objects load on demand, one\nquery at a time, unless the QuerySet asks for them up front.\n\n```python\n# Book has a ForeignKey to Author.\n# 1 query for the books, then 1 per book for its author.\nfor book in Book.objects.all():\n    print(book.author.name)\n\n# 1 query: an SQL join loads each author with its book.\nfor book in Book.objects.select_related(\"author\"):\n    print(book.author.name)\n\n# 2 queries: the authors, then all their books in one batch.\nfor author in Author.objects.prefetch_related(\"book_set\"):\n    print(author.name, [b.title for b in author.book_set.all()])\n```\n\n## Why it matters\n\nDjango matters because of what it makes the default. Its QuerySets build SQL\nwith the parameters kept apart from the query text, so values a user supplies\nare escaped by the database driver. Its templates escape the characters that are\nmost dangerous in HTML. Its CSRF protection checks a secret on every POST, and\nit stores passwords with PBKDF2 over SHA-256, a stretching method its\ndocumentation notes is recommended by NIST. A team writing ordinary Django code\ngets those protections without asking for them.\n\nThe same defaults set the shape of the risk. Each can be undone by one line,\nsuch as a raw query, a `mark_safe`, a `csrf_exempt` or `DEBUG = True` left on\nthe live server, and each of those lines looks harmless in review. The ORM makes\na similar trade with performance: it is easy to write a view whose query count\ngrows with the length of the page, and the Python reads the same either way.\n\nOur recommendation is to choose Django when the application is shaped by its\ndata: records that people create and edit, accounts with permissions, and staff\nwho need an admin screen over all of it. Keep each project on a supported\nrelease, choose an LTS while the A.B releases last, and write the end of support\nnext to the version. Run `manage.py check --deploy` against the production\nsettings in the pipeline, keep the secret key and the database password out of\nthe repository, and read the SQL the ORM writes for every page that matters. For\na site the client will mostly edit as pages, a content management system or\nstatic pages fit better than a framework.\n\n## What it looks like in practice\n\nFrom 2015 to 2022, as a web developer, the work included\n[Django web applications around an IPTV platform](/portfolio/built-and-maintained-django-apps-for-iptv/),\nthe parts of a round-the-clock service that people actually clicked on: new\nfeatures, bug fixes, and steady work on performance and stability, done across\nthe team. On a service like that, the page says, stability is the constraint the\nfeatures have to respect, and the applications kept gaining capability while\nstaying reliable for internal teams and customers.\n\nEarlier, from 2003 to 2014, as a full stack web developer,\n[a hundred web applications](/portfolio/developed-100-web-applications-using-html-html5/)\nwere built for clients who wanted very different things. Where a client needed\nsomething custom, the tools were HTML/HTML5, CSS/SCSS and Django; where they\nneeded something more standard that they could also manage themselves, WordPress\nor Joomla was the faster, more sensible answer. The page names the skill as\nknowing which was which, including talking a client out of a bespoke build they\ndid not need, or into one they did. That is the same line our recommendation\ndraws.\n\nThe [tech stack page](/tech-stack/) keeps both halves of that. Its web tier is\nstatic-first, with Django and PHP where there is an application to serve, and\nits list of languages treats SQL as a first-class language rather than something\nan ORM generates, because most of the performance work we are called in for\nlives there. For a Django application, that means the ORM writes the queries and\nsomeone still reads them.\n\n## Where it goes wrong\n\n- **A loop runs one query per row.** In the default fetch mode, reading a\n  foreign key that the QuerySet did not load runs a query for that one object,\n  so a list of a hundred books with their authors costs 101 queries. Templates\n  make it harder to see, because they call methods such as `all` without\n  parentheses. Use `select_related()` for foreign keys and one-to-one fields and\n  `prefetch_related()` for many-to-many fields and reverse foreign keys. On\n  Django 6.1 and later, the `FETCH_PEERS` mode batches those lookups into one\n  extra query, and `FETCH_RAISE` turns an unplanned query into an exception in\n  code that has to stay fast.\n- **Debug mode reaches production.** The deployment checklist says never to\n  enable `DEBUG` in production, because its error pages leak excerpts of source\n  code, local variables, settings and the libraries in use. With\n  `DEBUG = False`, Django will not serve requests at all until `ALLOWED_HOSTS`\n  holds a suitable value, and a wildcard there means validating the Host header\n  yourself. Run `manage.py check --deploy` against the production settings file,\n  which automates part of that checklist.\n- **The secret key sits in the repository.** `SECRET_KEY` protects sessions\n  under most session backends, every password reset token and all cryptographic\n  signing that names no other key, and the settings reference warns that a known\n  key can lead to privilege escalation and remote code execution. Load it from\n  the environment or a file, keep it out of version control, rotate it through\n  `SECRET_KEY_FALLBACKS`, and remove old keys from that list promptly.\n- **A safe default is switched off for one view.** QuerySets are parameterised,\n  but raw queries, `extra()` and `RawSQL` leave escaping to the developer;\n  templates escape HTML, but `mark_safe`, the `safe` filter and turning\n  autoescape off hand that job back too; `csrf_exempt` removes the check from a\n  view entirely. Each one deserves a stated reason in review, and HTML that\n  users store should be sanitised on input as well as output.\n- **A migration stops halfway.** On PostgreSQL and SQLite, every operation in a\n  migration runs inside one transaction by default, but MySQL has no\n  transactions around schema changes, so a migration that fails partway leaves\n  changes to unpick by hand. Read what `makemigrations` thinks changed, check\n  the SQL with `sqlmigrate` before it reaches production, and commit each\n  migration together with its model change.\n\n## Further reading\n\n- [Django documentation](https://docs.djangoproject.com/en/stable/) — the\n  current stable release's documentation, from the tutorial to the reference.\n- [Django: Deployment checklist](https://docs.djangoproject.com/en/stable/howto/deployment/checklist/)\n  — the settings to change before going live, part of which `check --deploy`\n  automates.\n- [Django: Database access optimization](https://docs.djangoproject.com/en/stable/topics/db/optimization/)\n  — QuerySet evaluation, fetching related objects and the habits that keep query\n  counts flat.\n- [Django: Migrations](https://docs.djangoproject.com/en/stable/topics/migrations/)\n  — the migration workflow, `sqlmigrate`, and how each database engine handles\n  schema changes.\n- [Security in Django](https://docs.djangoproject.com/en/stable/topics/security/)\n  — what the framework protects against by default and where that protection\n  stops.\n- [Download Django](https://www.djangoproject.com/download/) — the supported\n  release series with their mainstream and extended support dates.\n\n\u003chttps://engineer.company/glossary/django/\u003e\n","date_modified":"2026-10-20T21:59:50Z","description":"What Django is, how its ORM and migrations shape an application, which settings leak in production, and when it is the right framework to choose.","formats":{"gemtext":"https://engineer.company/glossary/django/index.gmi","gopher":"https://engineer.company/glossary/django/gophermap","html":"https://engineer.company/glossary/django/","json":"https://engineer.company/glossary/django/index.json","markdown":"https://engineer.company/glossary/django/index.md","pdf":"https://engineer.company/glossary/django/index.pdf"},"kind":"page","language":"en","title":"What is Django?","url":"https://engineer.company/glossary/django/","version":1}