settings.py is Django's control panel—database, installed apps, middleware, templates, static files, and security flags all live here (or in split settings modules for production).
Settings you touch early
DEBUG—Truein development only; never in productionSECRET_KEY— signs sessions/CSRF; keep secret, rotate if leakedALLOWED_HOSTS— hostnames the site will serve (required when DEBUG is False)DATABASES— default SQLite locally; PostgreSQL in productionINSTALLED_APPS,MIDDLEWARE,TEMPLATES,STATIC_URL
Environment-specific settings
Mature projects use settings/base.py, dev.py, prod.py and env vars for secrets—never commit production SECRET_KEY or DB passwords.
Important interview questions and answers
- Q: Why is DEBUG=False in production?
A: DEBUG exposes stack traces and sensitive settings to attackers—use logging and Sentry instead. - Q: Where should SECRET_KEY live?
A: Environment variable or secret manager—not in git. - Q: Default dev database?
A: SQLite (db.sqlite3)—fine for learning; PostgreSQL is standard for production Django.
Self-check
- What happens if ALLOWED_HOSTS is empty and DEBUG is False?
- Name two settings that must differ between dev and prod.