The Django setting that hands out your routes

What DEBUG = True exposes on a live Django site, a ten-second read-only check you can run across your hosts, and the settings change that stops it coming back.

Share
A server rack in shadow with one blade pulled out, and a glowing diagnostic panel floating in front of it

One setting decides whether your Django app tells the world its own structure. It is called DEBUG, it defaults to False, and it ends up True on production often enough that a single afternoon of scanning finds it.

This is a walk-through of what that setting exposes, how to check for it in about ten seconds per host, and what to change so it cannot come back on the next deploy. The check is read-only. You can run it against your own estate today.

The error page is the leak

Django is a Python web framework. DEBUG is the switch that decides how much detail the framework shows when something goes wrong. With DEBUG = False, a request for a page that does not exist returns a plain 404, and an unhandled exception returns a generic 500. With DEBUG = True, the framework replaces both with a diagnostic page built for the developer sitting at the console.

The setting is documented as a development aid, and the docs are blunt about production use: leaving it on is not supported (Django settings reference).

The reason it matters is what the diagnostic page contains. Two different pages, two different disclosures.

A 404 page lists your routes. When a path does not match, the debug page names the URLconf module and prints the patterns it tried, in order. That is your application's map: it tells an attacker which endpoints exist, what prefixes they live under, and often which framework features are wired in.

A 500 page prints your settings. When an exception is unhandled, the debug page renders a traceback that includes the settings dictionary: SECRET_KEY, database host and credentials, email configuration, API keys held in settings, ALLOWED_HOSTS, and the list of installed apps. SECRET_KEY alone is enough to forge signed session cookies and password-reset tokens for many applications.

So DEBUG = True is a handful of separate exposures: low-grade disclosure today, a full compromise the first time an exception escapes, which on a real application is a question of when.

Request a path that does not exist

One request per host. Any path that does not exist will do; the whole point is that you are asking for something invalid on purpose.

curl -s -o /dev/null -w '%{http_code}\n' https://app.example.com/definitely-not-a-real-path

A 404 tells you nothing yet. Look at the body:

curl -s https://app.example.com/definitely-not-a-real-path | grep -E 'DEBUG = True|URLconf'

If both appear, the host is running with DEBUG on. The giveaway sentence is Django's own: "You're seeing this error because you have DEBUG = True in your Django settings file."

Before you believe either result, run the same request on a host you know is healthy. Some applications answer every unknown path with the same 200 and an app shell, which makes a missing 404 look like a finding. Comparing a target host against a known-clean one is the difference between a scan and a measurement.

To sweep a list of hosts, keep the per-host output rather than a summary, because the evidence is the page itself:

while read -r host; do
  body=$(curl -s --max-time 10 "https://$host/zz-not-a-real-path")
  if grep -q 'DEBUG = True' <<<"$body"; then
    echo "DEBUG ON   $host"
  fi
done < hosts.txt

Turn it off, then set ALLOWED_HOSTS

1. Turn it off in the settings module that production actually loads.

# settings/production.py
DEBUG = False

Make it environment-driven rather than hard-coded, so a copied development settings file cannot silently reintroduce it:

import os
DEBUG = os.environ.get("DJANGO_DEBUG", "0") == "1"

2. Set ALLOWED_HOSTS in the same change. The moment DEBUG turns off, Django starts validating the Host header, and requests to a hostname that is not listed raise DisallowedHost — you get 400s instead of pages. The switch and the host list belong in one commit (settings reference).

3. Serve your own error pages. With DEBUG = False, Django looks for handler404 and handler500 templates and falls back to plain responses if they are missing. Defining them gives you control over what a failed request says — nothing about your framework or your paths (error views).

4. Keep exception detail in the logs, where only you can read it. Django's logging configuration captures a full traceback server-side even when the client gets a generic page, and the error-reporting docs cover wiring it to your monitoring (error reporting).

5. Check the deploy, not the repository. A settings file being right proves nothing about what is running. After the deploy, run the same curl and confirm the marker is gone. That check belongs in the release checklist, next to the one that confirms the health endpoint answers. For everything else worth confirming on a freshly built host, see the server hardening checklist.

Tutorial settings get copied into production

DEBUG is True in the settings file every Django tutorial starts with, and development settings get copied into production because they work. The failure is rarely a decision. It is a default carried forward. An environment variable with a safe default ("0") is the only version of this that survives contact with a rushed deploy.

If you run Django anywhere, the sweep above is ten minutes of work and it is worth doing before someone else does it for you. The number of hosts that fail it is the number of hosts that would hand over their route table on request.

## Convertkit Newsletter