Django deployment errors, fixed
Each guide explains one error you hit when taking Django to production, why it happens, and how to fix it, with settings you can copy. Every fix works on any host.
DisallowedHost: Invalid HTTP_HOST header
Your domain is missing from ALLOWED_HOSTS, or a health check is calling the server by its IP address. Read the guide
CSRF verification failed. Request aborted.
Forms work locally and fail with a 403 once the app is behind HTTPS and a proxy. Read the guide
Django static files not loading in production
The admin and your site have no CSS after switching DEBUG off, and /static/ returns 404. Read the guide
ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting
collectstatic or a deploy stops because Django has no folder to copy static files to. Read the guide
Django Server Error (500) only when DEBUG = False
Everything works until you switch DEBUG off, then every page is a bare 500 with no traceback. Read the guide
You have unapplied migrations / relation does not exist
The code expects tables or columns that the production database doesn't have yet. Read the guide
Too many redirects with SECURE_SSL_REDIRECT
ERR_TOO_MANY_REDIRECTS after turning on SECURE_SSL_REDIRECT behind a proxy or load balancer. Read the guide
The SECRET_KEY setting must not be empty
Django refuses to start because the key your settings read from the environment is missing. Read the guide
How to roll back a Django deploy (and bad migrations)
Undo a bad release without making the database worse: code, migrations and settings. Read the guide
Deploy Django to AWS: your options
Five ways to run Django on AWS, what each asks of you, and the Django traps on all of them. Read the guide
OperationalError: connection to server failed: Connection refused
Django can't reach the database: usually the host is still localhost, or port 5432 is blocked. Read the guide
FATAL: no pg_hba.conf entry ... no encryption (Postgres SSL required)
Your managed Postgres only accepts encrypted connections and Django isn't using one. Read the guide
FATAL: sorry, too many clients already (Django and Postgres)
Postgres refuses new connections because the app opened more than the server allows. Read the guide
ModuleNotFoundError: No module named 'psycopg2'
The Postgres driver is missing from production, or it failed to build. Read the guide
SQLite in production: database is locked, or data disappears
SQLite fails under several workers or loses its file when the app is redeployed. Read the guide
ModuleNotFoundError: No module named 'myproject.settings'
Django can't find or import your settings module in the production process. Read the guide
502 Bad Gateway with Django, gunicorn and nginx
The proxy is up, the app behind it isn't answering. Read the guide
[CRITICAL] WORKER TIMEOUT in gunicorn (Django)
A worker was killed because a request ran longer than the timeout. Read the guide
OSError: [Errno 28] No space left on device (Django)
Writes fail because logs, uploads, sessions or old Docker data filled the disk. Read the guide
Django health check failing: the deploy keeps rolling back
The load balancer marks your Django instance unhealthy though the site works in a browser. Read the guide
Django generating http:// links behind a proxy (redirect_uri_mismatch)
Emails and OAuth redirects use http:// although the site is served over https. Read the guide
python manage.py migrate hangs or locks the table
migrate sits for minutes because something holds a lock on the table. Read the guide
InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency
migrate refuses to run because the recorded history contradicts the dependencies. Read the guide
ModuleNotFoundError after deploy: works locally, fails in production
An import that works on your machine fails on the server. Read the guide
ValueError: Missing staticfiles manifest entry
A template asks for a static file the manifest doesn't list, and the page returns a 500. Read the guide
Django Docker container exits immediately (exit code 1, 3 or 127)
docker run starts your Django image and it stops straight away. Read the guide
smtplib.SMTPAuthenticationError (535) in Django production
Password resets and contact forms fail with an SMTP authentication or connection error. Read the guide
Django environment variables not read in production (.env ignored)
DEBUG stays on, a setting is empty or a KeyError appears because the server's environment isn't yours. Read the guide
DEBUG = True in production: how to check and fix it
Your live site shows Django's yellow debug pages: find out why and turn it off safely. Read the guide
Django users logged out after every deploy
Every deploy signs everyone out because the key or the session storage doesn't survive. Read the guide
Django logs empty in production (logging with DEBUG = False)
Errors and print() output don't show up in production logs. Read the guide
RuntimeWarning: DateTimeField received a naive datetime
A warning fills your logs and times may be off by hours on the server. Read the guide
Hosting Django for clients, and in the EU
For consultants, agencies and teams who host Django apps for other people: who owns the account, who pays, how to hand over, and where the data lives.
Host a Django app for a client without becoming their sysadmin, with Django Cloud
Settle account ownership, billing and on-call before the first deploy, and ship without a server to babysit. Read the guide
Django project handover checklist for clients, and how Django Cloud keeps it short
Accounts, secrets, runbook and removing your access, so the client never has to call you to restart the app. Read the guide
Who pays for client Django hosting? Three models, and how Django Cloud bills each
Three billing models for hosting on client work, with their risks and what to write in the contract. Read the guide
Host multiple client Django apps without a shared server, using Django Cloud
Why one server for many clients is a risk, and how to run many client apps from one place. Read the guide
Django maintenance retainer: what to monitor and promise, with Django Cloud
Define the work, the response times and the limits, and a retainer is easy to price and renew. Read the guide
Django staging environment for client projects, set up with Django Cloud
A second copy of the app where clients approve changes before they go live. Read the guide
Deploy Django to your client's AWS account with Django Cloud Self-hosted
A cross-account role instead of shared keys: the client keeps the account and can end your access at any time. Read the guide
Bring-your-own-cloud Django hosting: how Django Cloud works
A platform on top, your own cloud account underneath: ownership, direct billing and your choice of region. Read the guide
Django on AWS: Lightsail vs ECS vs App Runner, and what Django Cloud picks
Which AWS container service fits a small or medium Django app, in plain words. Read the guide
AWS Activate credits for Django: pay for hosting with Django Cloud Self-hosted
Credits only work when the app runs in your own AWS account. Here is how to stretch them. Read the guide
Migrate a Django app from Heroku to your own AWS account with Django Cloud
Settings, database and domain in the right order, with a safety net on the old side. Read the guide
Django hosting in the EU: choose your region with Django Cloud
App, database, build and DNS: where each one lives when you pick a European region. Read the guide
GDPR and Django hosting: what must stay in the EU? Django Cloud explains
The rules versus the habits: what GDPR actually requires of a Django app and its host. Read the guide
EU region vs digital sovereignty on AWS: where Django Cloud fits
An EU region is not the same as digital sovereignty. Know the difference before you promise it. Read the guide
Data processing agreement (databehandleraftale) for Django hosting, with Django Cloud
A databehandleraftale explained: who needs one, what it must say and what to ask your host. Read the guide
Django hosting for NIS2 and DORA clients: what suppliers must show, with Django Cloud
What banks, energy firms and public bodies will ask a small Django supplier, and how to be ready. Read the guide
Best AWS region for a European Django app, chosen in Django Cloud
Five European regions compared by the four things that actually matter. Read the guide