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.
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
- 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 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026