Django
1. Dependencies
# src/requirements.txt
Django
gunicorn
whitenoise
mysqlclient # or psycopg[binary] for PostgreSQL
2. Settings
At the end of settings.py — values from environment variables, trust in the proxy's HTTPS header and static files via WhiteNoise:
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 = ["https://" + h for h in ALLOWED_HOSTS]
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
STATIC_ROOT = BASE_DIR / "staticfiles"
MIDDLEWARE.insert(1, "whitenoise.middleware.WhiteNoiseMiddleware")
DATABASES = {"default": {
"ENGINE": "django.db.backends.mysql",
"HOST": os.environ["DB_HOST"], "PORT": os.environ["DB_PORT"],
"NAME": os.environ["DB_NAME"], "USER": os.environ["DB_USER"], "PASSWORD": os.environ["DB_PASSWORD"],
}}
In the "Environment variables" block set DJANGO_SECRET_KEY, DJANGO_ALLOWED_HOSTS (your domain; several domains separated by commas) and DB_* from the database card.

3. Project
- Create a project with the Python handler (version stable).
- Build command:
python -m venv .venv && pip install -r src/requirements.txt && cd src && python manage.py migrate --noinput && python manage.py collectstatic --noinput - Start command:
cd src && gunicorn mysite.wsgi --bind 0.0.0.0:$PORT --workers 2(replacemysitewith your project's package).
The build and start commands in the "Handler" block. - Connect the repository in the Git deploy block with the
srcdirectory and click "Deploy". Create the administrator once in the "Terminal":cd src && python manage.py createsuperuser.
4. Uploaded files
Put MEDIA_ROOT inside the project, for example BASE_DIR / "media" — a deploy does not touch files that are not in the repository. Gunicorn does not serve them with DEBUG=False: for public files use S3 storage or a separate static project.
5. If something goes wrong
- "Bad Request (400)". The domain is not in
DJANGO_ALLOWED_HOSTS. - "CSRF verification failed" when signing in to the admin.
CSRF_TRUSTED_ORIGINSwith thehttps://address of your domain is missing. - The admin has no styles.
collectstaticwas not run, or WhiteNoise is not enabled. - Endless redirects to https.
SECURE_SSL_REDIRECTis on withoutSECURE_PROXY_SSL_HEADER; the panel already redirects to HTTPS anyway.