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
| Framework | Start command |
|---|---|
| Django | gunicorn myproject.wsgi --bind 0.0.0.0:$PORT |
| Flask | gunicorn app:app --bind 0.0.0.0:$PORT |
| FastAPI | uvicorn 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
collectstaticand 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.