A small Django app backed by PostgreSQL,
ready to run as a web service on Cosmoner. It has the
Django admin enabled, a Note model to manage in it, and a page that lists
the notes.
config/settings.pyreads everything that differs between environments from environment variables.core/holds the model, its migration, the views and the admin.GET /healthanswers200when the app and the database both respond.
The app is built automatically from pyproject.toml and uv.lock. Each time
it starts, bin/start.sh (named in the Procfile):
- collects static files, which WhiteNoise then serves, compressed and with cache-busting names;
- runs
python manage.py migrate; - creates the first admin account, if
DJANGO_SUPERUSER_USERNAMEandDJANGO_SUPERUSER_PASSWORDare set and that account does not exist yet; - starts Gunicorn on the port in the
PORTenvironment variable, which Cosmoner sets for you.
This app needs a PostgreSQL database and a DATABASE_URL secret before it can
start.
- In your Cosmoner project, create a PostgreSQL database.
- Store its connection string as a
secret named
DATABASE_URL. Use the internal host, which apps in the same project connect to. - Select the button above, copy the template to your GitHub account, and
deploy your copy. The wizard can fill in every setting from
.cosmoner/deployment.yaml, and asks you for two values:
| Variable | What to enter |
|---|---|
DJANGO_SECRET_KEY |
A long random string, e.g. the output of python -c "import secrets; print(secrets.token_urlsafe(50))" |
DJANGO_SUPERUSER_PASSWORD |
The password for the admin account |
Once the app is live, sign in at /admin/ as admin. The account is only
created when it does not exist, so changing DJANGO_SUPERUSER_PASSWORD later
does not change the password; do that in the admin.
Optional variables:
| Variable | Default |
|---|---|
DJANGO_ALLOWED_HOSTS |
.cosmoner.com,localhost,127.0.0.1. Add your custom domain here, comma-separated. |
DJANGO_CSRF_TRUSTED_ORIGINS |
Empty. Only needed for forms posted from another origin. |
WEB_CONCURRENCY |
2 Gunicorn workers. |
Requires Python 3.13, uv and a PostgreSQL database.
uv sync
export DATABASE_URL=postgresql://user:password@localhost:5432/app
export DJANGO_DEBUG=true
uv run python manage.py migrate
uv run python manage.py createsuperuser
uv run python manage.py runserverOpen http://localhost:8000, and the admin at http://localhost:8000/admin/.
After changing a model, run uv run python manage.py makemigrations and commit
the new migration; it is applied on the next deploy.
MIT