Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
Python & Django

Getting Django Running Properly in Production

Last updated:

The settings that matter

  1. Debug off, without exception, in production
  2. Allowed hosts set correctly
  3. Secret key from the environment, unique per environment
  4. Database credentials from the environment
  5. Secure cookie and HTTPS settings enabled
Debug left on in production exposes your settings, your database queries and your stack traces to anyone who triggers an error. It is the single most damaging misconfiguration.

Static and media files

  • Static files collected and served by the web server or a CDN, not by Django
  • Media uploads stored outside the code directory, ideally in object storage
  • Correct cache headers on static assets
  • Uploaded files never served from a path that could execute them

Migrations in the deployment

Migrations should run as a defined step in deployment, not manually afterwards. Manual migrations are forgotten, and a code version expecting a column that does not exist fails immediately.

Design them backwards-compatible where possible, so code can roll back without a database rollback.

The runtime stack

ComponentRole
Application serverRuns the Django code
Reverse proxyTLS, static files, buffering
Process supervisorRestarts anything that exits
Worker processesBackground tasks
SchedulerRecurring work

The development server should never run in production. It is single-threaded, unoptimised and explicitly not intended for it.

Health checks and logging

A health endpoint that checks the database and any critical dependency, so monitoring knows whether the application is actually working rather than merely running.

Logs to standard output, collected centrally. A log file on a server nobody reads is not logging.

Frequently asked questions

Containers or plain deployment?

Containers give consistency and add operational complexity. For a single application and a small team, plain deployment is frequently simpler.

How do we handle static files?

Collected at deploy time and served by the web server or a CDN. Never by Django in production.

What about zero-downtime deployment?

Achievable with an atomic switch and graceful shutdown. Backwards-compatible migrations make it practical.

Where should settings live?

Environment variables, with a settings module that reads them and fails fast if something required is missing.

Keep reading

Not sure your production settings are right?

Debug, allowed hosts and secret key are the three to check first. Quick to verify.

Book a free 30-minute call Get a project estimate WhatsApp us

Related services

What we build for problems like this one

Custom Software DevelopmentWeb DevelopmentMachine Learning