Skip to content

/errors/django/improperlyconfigured-settings-not-configured

ImproperlyConfigured: Requested setting …, but settings are not configured

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated 2026-10-20
tool
Django
exit code
1
versions
Django 4.2 – 6.1
os
any

Django raises django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured when something reads django.conf.settings before Django knows which settings module to use. manage.py, wsgi.py and asgi.py set DJANGO_SETTINGS_MODULE for you; plain scripts, notebooks and test runners do not.

Reproduce the error

bash
python -c "from django.conf import settings; print(settings.DEBUG)" 2>&1 | tail -1; exit "${PIPESTATUS[0]}"

Output · exit 1

django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Fix: point Django at your settings

bash
mkdir -p mysite && printf 'SECRET_KEY = "dev"\nDEBUG = True\nUSE_TZ = True\n' > mysite/settings.py && touch mysite/__init__.py
DJANGO_SETTINGS_MODULE=mysite.settings python -c "from django.conf import settings; print('DEBUG =', settings.DEBUG)"

Output

DEBUG = True

Standalone scripts that use models

Set the variable and call django.setup() before importing anything that touches models:

python
import os
import django

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

from polls.models import Question   # import models only after setup()
print(Question.objects.count())

pytest

pyproject.toml
[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "mysite.settings"

This option is read by the pytest-django plugin.

Sources