Skip to main content
You will deploy an existing Django project, with a Dockerfile, to Reliant hosting with a managed Postgres. Forge reads the Dockerfile, requirements.txt and manage.py and writes its declarations beside them; your Django code changes only where production settings need it (below). The detector output here is from Forge v1.10.1-0.20261123064811-54313eead62f.

Before you begin

  • Docker, and the project in a git repository with a root Dockerfile that builds on its own.
  • Forge: reliant forge inside Reliant, or npx -y @reliantlabs/forge@latest anywhere else.
  • For a deploy that lasts, a Reliant account with app hosting billing.

What the Dockerfile must do

Serve with gunicorn, bound to 0.0.0.0, never manage.py runserver. Collect static files at build time:
Dockerfile
The detector reads the port from EXPOSE (or the compose service’s published port, a --bind/--port in the command, or ENV PORT) and sets PORT. Serve the collected files with WhiteNoise (whitenoise.middleware.WhiteNoiseMiddleware): there is no nginx in front of the app. collectstatic imports your settings, so give it a throwaway key at build time instead of baking the real one into a layer.

Production settings

Hosting serves the app on a generated *.reliantlabs.dev hostname, TLS terminated at the ingress. Read everything from the environment:
mysite/settings.py (excerpt)
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY", "dev-insecure") is the classic hole: prod runs on a key that is in your repository. ALLOWED_HOSTS must hold the URL hosting gives you, so you learn it after the first deploy (env status) and set it then; until it does, every request is a 400. Without CSRF_TRUSTED_ORIGINS, Django 4+ rejects every form POST over HTTPS, the admin login included. SECURE_PROXY_SSL_HEADER stops SECURE_SSL_REDIRECT from looping.

Postgres and migrations

With psycopg (or psycopg2) in requirements.txt, the detector adds a managed Postgres on staging and prod and passes its URL as DATABASE_URL; with manage.py present it adds a migrate job, python manage.py migrate, run from the app’s image before every rollout. Don’t also migrate in the container’s start command.
1

Preview and adopt

terminal
Output (trimmed)
With no compose file, dev runs the command on your machine beside a local Postgres; change it to python manage.py runserver 0.0.0.0:$PORT in deploy/kcl/dev/main.k if you prefer. Then write the files and commit them:
terminal
2

Declare the settings and the secret

With no compose file the detector can’t see your env vars, so add them. In deploy/kcl/prod/main.k, on both the api and the migrate workload (manage.py migrate imports your settings too):
deploy/kcl/prod/main.k (excerpt)
Replace the existing api and migrate bindings with these entries; don’t add duplicate bindings. Both workloads reference the same managed secret, so set its value once:
terminal
Dev reads the same names from the gitignored secrets/dev.yaml (DJANGO_SECRET_KEY: dev-only) once you add the ManagedSecret to deploy/kcl/dev/main.k.
3

Build, render, lint, deploy

terminal
The deploy builds the image, runs migrate, then rolls out api. Without app hosting billing it is queued and exits 7 with the billing link. The default size is 250m CPU and 1 GiB per workload; two gunicorn sync workers fit comfortably.With no account, npx -y @reliantlabs/forge@latest env deploy prod --claimable publishes a 72-hour preview (adopt with --kind app --claimable first, and run --plan-only to check it fits). It is one service at 125m CPU and 128 MiB, so run a single gunicorn worker (--workers 1); it gets no secret values and no outbound internet until claimed. A SECRET_KEY read with os.environ[...] therefore won’t start unclaimed: claim first, or sign in. See Deploy without an account.
4

Verify

terminal
A 200 from the admin login proves ALLOWED_HOSTS, static files and the database connection at once. obs check exits 0 proven good, 1 regressed, 2 not proven, 8 the wait ran out. Without an OpenTelemetry SDK (opentelemetry-instrumentation-django) it is 2, no_request_telemetry: not proven good. See Send OpenTelemetry from any app.

Django gotchas

  • 400 Bad Request on every page: the host is not in ALLOWED_HOSTS. Add it, redeploy.
  • 403 CSRF verification failed on POST: CSRF_TRUSTED_ORIGINS lacks https://<host>.
  • Celery: a worker is a second workload (kind = "worker", same image, command = ["celery", "-A", "mysite", "worker"]). It needs billing; an anonymous deploy allows one service only.
  • Media uploads: the container disk is scratch and is lost on every rollout. Use object storage.
See also: Bring an existing app, Managed Postgres, Secrets, Hosting limits.