Organize Django Settings
When modifying src/project/settings.py, enforce this structure.
Section Format
Every logical group of settings gets a banner header:
# =============================================================================
# SECTION NAME
# =============================================================================- Banner lines are exactly 77 characters (
#+ 75=characters) - Section name is UPPERCASE
- One blank line before each banner (except at top of file)
- No blank lines between the banner and the first setting in that section
- No inline comments explaining what standard Django settings do — the section header is enough
Section Order
Settings must appear in this order. Omit sections that have no settings.
- Imports and
BASE_DIR(no banner — these are preamble) - LOGGING
- SECURITY —
SECRET_KEY,DEBUG,ALLOWED_HOSTS, CORS, CSRF, cookie settings - APPLICATION DEFINITION —
INSTALLED_APPS,MIDDLEWARE - URLS AND WSGI —
ROOT_URLCONF,WSGI_APPLICATION - TEMPLATES
- AUTH —
AUTH_USER_MODEL,AUTH_PASSWORD_VALIDATORS,LOGIN_URL - DATABASE
- SESSIONS
- CACHING
- INTERNATIONALIZATION —
LANGUAGE_CODE,TIME_ZONE,USE_I18N,USE_TZ - STATIC FILES —
STATIC_URL,STATIC_ROOT,DEFAULT_AUTO_FIELD - CELERY — all
CELERY_*settings - Any additional project-specific sections in alphabetical order
INSTALLED_APPS Sub-grouping
Within INSTALLED_APPS, group entries with inline comments:
INSTALLED_APPS = [
# Django core
"django.contrib.admin",
...
# Third-party
"corsheaders",
...
# Project apps
"products.apps.ProductsConfig",
"orders.apps.OrdersConfig",
]Project apps must use the dotted path to their AppConfig subclass (e.g., "myapp.apps.MyAppConfig"), not the short app name.
Rules
- Do NOT add Django docs URLs as comments (e.g.,
# https://docs.djangoproject.com/...) - Do NOT add "Quick-start" or "Generated by" boilerplate comments
- Keep
AUTH_PASSWORD_VALIDATORScompact — one dict per line when the only key is"NAME" - When adding a new setting, place it in the correct existing section. Create a new section only if none fit.