Django hosting

Deploy a Django app with gunicorn and Postgres

To deploy Django on Makofy, add gunicorn to requirements.txt, read secrets and DATABASE_URL from environment variables, allow your .makofy.sh host in ALLOWED_HOSTS, and set a start command such as gunicorn mysite.wsgi --bind 0.0.0.0:$PORT. A Django app plus managed Postgres costs $6.50 a month ($3.50 Starter + $3 Postgres 18 with nightly backups), with a 7-day free trial.

Last updated · By the Makofy team (Muncar Ventures LLC)

How Makofy builds a Django project

Without a Dockerfile, Makofy builds Python on python:3.12-slim and installs requirements.txt (or pyproject.toml, or a Pipfile). For Django it guesses a start command: gunicorn with a project module named config when gunicorn is in your requirements, and Django’s development server otherwise. Neither guess fits most projects, so the reliable path is to add gunicorn and give Makofy your own start command.

SituationWhat Makofy would runWhat to do
Project module is config, gunicorn installedgunicorn config.wsgiWorks; still consider your own command for migrations.
Project module is anything else (mysite)A module that doesn’t existSet the start command to gunicorn mysite.wsgi ...
gunicorn not in requirementsmanage.py runserverAdd gunicorn: runserver is not for production.
A Dockerfile in the repoYour DockerfileFull control over system packages and steps.

Settings checklist for production

  • SECRET_KEY from an environment variable, never from the repo.
  • DEBUG off unless an environment variable turns it on.
  • ALLOWED_HOSTS must include your free Makofy hostname (.makofy.sh covers it) and your custom domain.
  • CSRF_TRUSTED_ORIGINS needs the full origin with scheme, for example https://myapp--myworkspace.makofy.sh, or logins and admin forms fail with a CSRF error.
  • DATABASES from DATABASE_URL, parsed with dj-database-url.
  • Static files collected with collectstatic and served by WhiteNoise, so you don’t need a separate web server.
# mysite/settings.py (production-relevant parts)
import os
import dj_database_url

SECRET_KEY = os.environ["SECRET_KEY"]
DEBUG = os.environ.get("DEBUG") == "1"
ALLOWED_HOSTS = [".makofy.sh", "www.example.com"]
CSRF_TRUSTED_ORIGINS = ["https://*.makofy.sh", "https://www.example.com"]

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

MIDDLEWARE.insert(1, "whitenoise.middleware.WhiteNoiseMiddleware")
STATIC_ROOT = BASE_DIR / "staticfiles"
# requirements.txt
Django==5.1.*
gunicorn==23.*
dj-database-url==2.*
psycopg[binary]==3.2.*
whitenoise==6.*

Deploy it, step by step

  1. Start the 7-day free trial at makofy.com (card required, nothing charged until it ends).
  2. Add the Postgres add-on ($3/month) and copy its connection URL from the dashboard.
  3. Create the app from your GitHub repository and branch, or run makofy deploy from the project folder after installing the CLI.
  4. Set environment variables: SECRET_KEY, DATABASE_URL (the URL you copied) and anything else your settings read.
  5. Set the start command (below) so migrations and collectstatic run before gunicorn starts.
  6. Deploy and open https://<app>--<workspace>.makofy.sh/admin/. For the first admin user, set DJANGO_SUPERUSER_USERNAME, DJANGO_SUPERUSER_EMAIL and DJANGO_SUPERUSER_PASSWORD and add python manage.py createsuperuser --noinput || true && to the start command for one deploy.
makofy deploy --command "python manage.py migrate --noinput && python manage.py collectstatic --noinput && gunicorn mysite.wsgi --bind 0.0.0.0:$PORT --workers 2"

The start command runs through a shell, so && chains steps and $PORT expands to the port Makofy assigns (8080 by default). Running migrations at startup is the simplest approach for a single instance; if a migration fails, the new version never becomes healthy, so Makofy marks the deploy unhealthy and redeploys the previous healthy version.

Celery, scheduled tasks and Redis

Run Celery as a second Makofy service from the same repository with the background worker type and a start command like celery -A mysite worker --concurrency 2. Add Redis 8 ($2/month) as the broker and put its connection URL in REDIS_URL. Periodic jobs can run as a cron service that calls a management command, for example python manage.py clearsessions, on a 5-field schedule.

Picking an instance type

Each gunicorn worker is a full copy of your Django project in memory. On Starter (512 MB, 0.5 vCPU, $3.50) two workers is a sensible ceiling. Basic (1 GB, 1 vCPU, $6) gives room for three or four workers and bigger dependencies; Pro (2 GB, 2 vCPU, $12) suits busier sites and is protected first when the node is under load. An admin-only or internal app can use Nap ($1.50): it sleeps after 15 idle minutes and wakes in about 2 to 6 seconds.

StackServicesMonthly price
Django + PostgresStarter + Postgres$6.50
Django + Celery + Postgres + RedisBasic + Starter worker + Postgres + Redis$14.50
Internal admin toolNap + Postgres$4.50

FAQ

Frequently asked questions

What does it cost to host Django with Postgres on Makofy?

$6.50/month: $3.50 for an always-on Starter app and $3 for managed Postgres 18 with nightly backups. There is a 7-day free trial with a card.

Why does my Django app fail with a CSRF error after deploying?

Django needs your HTTPS origin in CSRF_TRUSTED_ORIGINS. Add https://<app>--<workspace>.makofy.sh (or https://*.makofy.sh) and your custom domain.

How do I run Django migrations on Makofy?

Put python manage.py migrate --noinput && in front of the gunicorn command in your start command, so migrations run on every deploy before the app starts.

How are static files served?

Use WhiteNoise and run collectstatic in the start command or a Dockerfile; Django then serves its own static files efficiently.

Can I run Celery workers next to Django?

Yes. Deploy the same repo as a background worker with a Celery start command, and add Redis ($2/month) as the broker.

Related

Deploy your app in a few minutes.

Connect a GitHub repo or run makofy deploy. Flat price per app, 7-day free trial, card required.

Start free trial