ImproperlyConfigured 🐍 Python

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

  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 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.