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

  • migrate runs 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)