In short: turn DEBUG off, take the secret key out of the code, list your real addresses in ALLOWED_HOSTS and enforce HTTPS. Leave Django's built-in protection on, and run a version that still gets security updates.
What has to change from your own machine?
A new Django project is set up for development on your own machine. That is convenient there, and a risk on a server anyone can reach. So Django's documentation has a list of its own for the step to production.
- our check reads this
- our check does not read this
Part of that list can be checked with the command manage.py check --deploy. Django adds that you should run it with your production settings, not with your local ones.
DEBUG off
With DEBUG on, Django shows a detailed page when something fails. It holds excerpts of source code, local variables, settings and the libraries in use. The documentation is firm about it: never enable debug in production.
The runserver command is meant for development only as well. In production, use a real application server.
The secret key outside the code
Django uses SECRET_KEY to sign sessions and tokens, among other things. The key must be long, random and kept secret. Keep it out of version control, and do not use it anywhere else.
In production, read the key from an environment variable or from a file on the server. If you have to replace it, the old one can stay in SECRET_KEY_FALLBACKS for a while. Remove it from there in good time.
Which addresses are allowed?
ALLOWED_HOSTS lists the domain names your site answers on. With DEBUG off, Django does not work without it. It protects against part of the attacks that use forged requests.
A wildcard is allowed, but then you have to check the Host header of each request yourself. Code that reads that header straight from request.META goes around this protection.
HTTPS and cookies
A site where people sign in should use HTTPS everywhere. Protecting only the sign-in page is not enough, because the same session cookie also travels over plain connections. Your web server redirects all traffic to HTTPS.
Also turn on SESSION_COOKIE_SECURE and CSRF_COOKIE_SECURE. If a proxy sits in front of your application, set SECURE_PROXY_SSL_HEADER with care. Django warns that getting it wrong can itself open a hole.
Leave the built-in protection on
Django protects against the best-known attacks by default. The risk starts where that protection is switched off.
- Templates escape characters that can be dangerous. Be careful with mark_safe, the safe filter and templates with autoescape turned off.
- CSRF protection checks every form that changes something. Use csrf_exempt only when there is really no other way.
- QuerySets build their SQL with parameters. With raw, extra and RawSQL you have to do that yourself, so use them sparingly.
- The clickjacking middleware stops your site from being shown inside someone else's frame.
Uploads and logging
Files your users upload cannot be trusted. A file can look like an image and still contain HTML. Django advises serving uploads from a separate domain, not from a subdomain of your own site. Also limit the request size in your web server.
Review your logging before you go live, and check that it works once traffic arrives. Error reports by email work with little traffic but do not scale well.
Does your version still get updates?
Django releases security updates for a limited number of versions at a time. On 1 December 2026 those are 5.2, 6.0 and 6.1. Version 5.2 is the LTS release and gets updates until April 2028. An older version gets no more security updates.
What we check of this
We read the settings and code of your Django project for seven of the points above. They are DEBUG, the secret key in the code and ALLOWED_HOSTS. We also look at the CSRF protection, the security middleware, raw SQL built from strings and escaping switched off in templates. We do not run your code for this; we read the files.
How your server is set up, we do not see. So we do not check whether you serve uploads separately or whether your logging works. We change nothing.
Join the pilotSources, opened on 1 December 2026
- Django: deployment checklist (version 6.1)
- Django: security in Django (version 6.1)
- Django: download and supported versions
Written by the BlueLandscape team with the help of AI. Every statement was checked against the source above.