ImproperlyConfigured Python Origin: Application & API Last updated 12 Oct 2026

django.core.exceptions.ImproperlyConfigured: settings are not configured / SECRET_KEY must not be empty

Django can’t load its settings — DJANGO_SETTINGS_MODULE unset, a required setting missing, or an environment variable not provided.

Exact message you may see Requested setting INSTALLED_APPS, but settings are not configuredThe SECRET_KEY setting must not be empty
Seen on: Python

Meaning

Running scripts outside manage.py, missing env vars in production (SECRET_KEY, DATABASE_URL) and wrong settings module paths all raise ImproperlyConfigured.

Common causes

  • DJANGO_SETTINGS_MODULE not set for standalone scripts
  • SECRET_KEY / database env vars missing
  • Settings module path typo
  • Missing database driver (psycopg)

⚡ Quick fix

  1. Set DJANGO_SETTINGS_MODULE=project.settings
  2. Call django.setup() in standalone scripts
  3. Provide required env vars in production

Detailed fix by platform

Python

  1. python
    import os, django
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
    django.setup()

How to diagnose

  1. Setting — Which setting is named?
  2. Env — Are env vars loaded in this process?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

1000 — Cloudflare Error 1000: DNS points to prohibited IP (Cloudflare)1000AADSTS90002 — AADSTS90002: Tenant 'x' not found (Azure)AADSTS90002AH00558 — Apache: AH00558: apache2: Could not reliably determine the server's fully qualified domain name (Nginx / Apache)AH00558api_version_invalid — API Error: Invalid or unsupported API version (API)api_version_invalidAzureWebJobsStorage — Azure Functions: Value cannot be null. (Parameter 'connectionString') / Missing value for AzureWebJobsStorage (Azure)AzureWebJobsStorageConnectionString property has not been initialized — InvalidOperationException: The ConnectionString property has not been initialized (.NET)ConnectionString prop…DisallowedHost — django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'x'. You may need to add 'x' to ALLOWED_HOSTS. (Python)DisallowedHostdivergent branches — hint: You have divergent branches and need to specify how to reconcile them. (Git)divergent branchesImproperl…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.