Good Code
The good version makes secrets and host rules explicit per environment. Production can fail fast when required values are missing.
Lesson 08
Load sensitive and environment-specific settings from the environment instead of hard-coding production behavior.
import os
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
DEBUG = os.environ.get("DJANGO_DEBUG") == "1"
ALLOWED_HOSTS = os.environ["DJANGO_ALLOWED_HOSTS"].split(",")
CSRF_TRUSTED_ORIGINS = [
origin
for origin in os.environ.get("DJANGO_CSRF_TRUSTED_ORIGINS", "").split(",")
if origin
]SECRET_KEY = "dev-secret"
DEBUG = True
ALLOWED_HOSTS = ["*"]
CSRF_TRUSTED_ORIGINS = ["https://*"]The good version makes secrets and host rules explicit per environment. Production can fail fast when required values are missing.
The bad version ships permissive defaults. A reviewer cannot tell whether it is local-only code or production configuration waiting to leak.