Interview Prep/Build Tools (Java, Node.js, Python, .NET)/Python builds (pip, venv, requirements.txt)
What does a Django deployment involve beyond running the app?
IntermediateHands-onPython builds (pip, venv, requirements.txt)
Answer
Short answer
Besides running it with gunicorn, a Django deployment needs: database migrations (migrate), collecting static files (collectstatic) for Nginx/CDN, production settings from environment variables (DEBUG=False, SECRET_KEY, ALLOWED_HOSTS, DATABASE_URL), and a deployment check.
Typical release steps
pip install -r requirements.txt
python manage.py check --deploy # warns about insecure settings
python manage.py migrate --noinput # apply DB schema changes
python manage.py collectstatic --noinput # gather CSS/JS into STATIC_ROOT
gunicorn myproject.wsgi:application -w 4 -b 0.0.0.0:8000
settings.py reading env vars
import os
DEBUG = os.getenv("DJANGO_DEBUG", "False") == "True"
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
ALLOWED_HOSTS = os.getenv("DJANGO_ALLOWED_HOSTS", "").split(",")
In Kubernetes
migrateruns as a Job or Helm pre-upgrade hook, once, before the new pods roll out.- Static files go to S3/Blob (via
django-storages) or are served by Nginx/WhiteNoise.
Common mistakes
DEBUG=True in production (leaks settings and stack traces), and DisallowedHost errors from an empty ALLOWED_HOSTS.
What to say in the interview
"Django needs migrate and collectstatic on release, settings from environment variables with DEBUG off, and gunicorn to serve it. In Kubernetes I run migrations as a one-off Job before rollout and serve static files from object storage or WhiteNoise."
All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Python apps: pip, venv & requirements.txt
More on Python builds (pip, venv, requirements.txt)
How do you install dependencies and run a Python application?BeginnerWhat is a Python virtual environment and why do we need it?BeginnerWhat is requirements.txt and how do you pin versions?BeginnerHow do you run a Flask application in development and in production?BeginnerWhat is gunicorn and how many workers should you run?BeginnerWhat is the difference between WSGI and ASGI?Intermediate