Documentation menu

Deploy Django on Light Cloud - a Python container on port 8000, with environment-driven settings, startup migrations, and WhiteNoise static files.

Deploy Django

Django is detected from your dependencies and runs as a Python container on port 8000. No Dockerfile needed - one is generated unless the repo has its own.

Serve it#

Bind 0.0.0.0 on the routed port - PORT is set to it:

gunicorn myproject.wsgi --bind 0.0.0.0:$PORT

Settings from the environment#

Containers receive environment variables at runtime - read them in settings.py:

import os

SECRET_KEY = os.environ["SECRET_KEY"]
DEBUG = os.environ.get("DEBUG", "false") == "true"
ALLOWED_HOSTS = ["*"]  # or the exact hosts you serve

Database#

Provision managed PostgreSQL and read DATABASE_URL - dj-database-url turns it into the settings dict:

import dj_database_url

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

Keep sslmode=require from the connection string as-is.

Migrations#

Run them where the database is reachable. The image build has no runtime variables, so the startup command is the natural place:

python manage.py migrate && gunicorn myproject.wsgi --bind 0.0.0.0:$PORT

Or run them from your laptop against the same DATABASE_URL - the connection string works anywhere.

Static files#

A container serves everything, static files included. The usual pattern is WhiteNoise: collectstatic during the build, WhiteNoise serving the result. Heavy asset traffic can move to its own static site later.