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.
Requested setting INSTALLED_APPS, but settings are not configuredThe SECRET_KEY setting must not be empty 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
- Set DJANGO_SETTINGS_MODULE=project.settings
- Call django.setup() in standalone scripts
- Provide required env vars in production
Detailed fix by platform
Python
- python
import os, django os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") django.setup()
How to diagnose
- Setting — Which setting is named?
- 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:
Similar errors
Most viewed in Python
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 12 Oct 2026