All tutorials
App DeploymentIntermediate

Deploy a Python App (Django, Flask or FastAPI)

Configure Gunicorn or Uvicorn, static files and migrations to run Python web apps in production.

Hostn.ME Team 9 min read 18 viewsUpdated November 22, 2026

Python apps need a production-grade server instead of the built-in dev server. Here's the setup for each framework.

1. Pin your dependencies

pip freeze > requirements.txt
echo "python-3.12" > runtime.txt

2. Choose a start command

FrameworkStart command
Djangogunicorn myproject.wsgi --bind 0.0.0.0:$PORT
Flaskgunicorn app:app --bind 0.0.0.0:$PORT
FastAPIuvicorn main:app --host 0.0.0.0 --port $PORT

Add gunicorn or uvicorn[standard] to requirements.txt.

3. Django production settings

import os
DEBUG = False
ALLOWED_HOSTS = ["yourdomain.com", ".hostn.app"]
SECRET_KEY = os.environ["SECRET_KEY"]
STATIC_ROOT = BASE_DIR / "staticfiles"

Use WhiteNoise to serve static files:

MIDDLEWARE.insert(1, "whitenoise.middleware.WhiteNoiseMiddleware")

4. Release command

Set a release command so migrations run before each deploy goes live:

python manage.py migrate && python manage.py collectstatic --noinput

5. Background tasks

Add a worker process for Celery or RQ:

worker: celery -A myproject worker -l info

Attach the Redis add-on and use its REDIS_URL as your broker.

6. Troubleshooting

  • 502 Bad Gateway → your app isn't binding to $PORT
  • Static files 404 → run collectstatic and check WhiteNoise
  • DisallowedHost → add your domain to ALLOWED_HOSTS

Stuck on a step?

Our AI assistant knows every tutorial, and a real engineer is one click away.