All documentation

Django

Django with PostgreSQL from Git: requirements.txt, Procfile, migrations, static files and settings from variables.

What the repository needs

The platform detects Python by requirements.txt and builds the image on python:3.12-slim: pip install -r requirements.txt, then starts from the Procfile.

requirements.txt:

Django>=5.1
gunicorn
dj-database-url
psycopg[binary]
whitenoise

Procfile in the root (replace mysite with your project name):

web: gunicorn mysite.wsgi --bind 0.0.0.0:$PORT
release: python manage.py migrate --noinput && python manage.py collectstatic --noinput
  • web is the website. The port comes in PORT, 8000 by default.
  • release runs before startup on every start: migrations and collecting static files. If the command fails, the new version does not start. More in Several processes in one app.

settings.py

Take secrets and addresses from variables:

import os
import dj_database_url

SECRET_KEY = os.environ["SECRET_KEY"]
DEBUG = os.environ.get("DEBUG", "0") == "1"
ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "").split(",")
CSRF_TRUSTED_ORIGINS = os.environ.get("CSRF_TRUSTED_ORIGINS", "").split(",")

DATABASES = {"default": dj_database_url.config(conn_max_age=600)}

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "whitenoise.middleware.WhiteNoiseMiddleware",
    # … the rest
]
STATIC_ROOT = BASE_DIR / "staticfiles"
STORAGES = {
    "staticfiles": {"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage"},
}

Launch

  1. “New resource” → “Database” → PostgreSQL 16.
  2. “New resource” → “App”, the repository link. Plan — Small or larger for several gunicorn workers.
  3. In the app's “Variables” tab:
SECRET_KEY=a-long-random-string
DEBUG=0
ALLOWED_HOSTS=myapp-abc123.example.uz,shop.example.uz
CSRF_TRUSTED_ORIGINS=https://myapp-abc123.example.uz,https://shop.example.uz

Use the app address from the resource card and your own domain instead of the examples.

  1. In the database: “Connection” tab → choose the app → “Connect”. DATABASE_URL arrives by itself, and dj-database-url reads it.
  2. Deploy. The build log is in the “Deploy” tab; gunicorn and migration output is in the “Log” tab.

Superuser

Open the app's “Console” tab and run:

python manage.py createsuperuser

Uploads

Every deploy starts from a clean disk. Point MEDIA_ROOT to a persistent volume (for example /app/data/media, “Settings” tab) or to external S3 storage.

Background jobs

A Celery worker can run next to the site via a worker: line in the same Procfile, and periodic jobs via the “Schedule” tab. See Several processes in one app and Scheduled jobs.