Deploy Django

Deploy a Django web app with PostgreSQL, Gunicorn and HTTPS in one click.

Deploy Django

Just deployed

/var/lib/postgresql/data

Deploy and Host Django on Railway

Django logo

Django is the batteries-included Python web framework, with 91,000+ GitHub stars: ORM, admin panel, authentication and migrations out of the box. This template deploys a Django app with a PostgreSQL database, Gunicorn and HTTPS on Railway in a few minutes. Heroku's always-on dyno plus database starts at $12/month — a small Django app on Railway typically runs for $3–8/month.


What This Template Deploys

ServicePurpose
ServerDjango app built from GitHub, served by Gunicorn with WhiteNoise for static files (port 8000, public HTTPS domain). Runs migrations and collectstatic on start.
PostgresPostgreSQL with SSL. Connection details are passed to Django as PG* variables.
Persistent VolumeMounted on Postgres at /var/lib/postgresql/data — your data survives redeploys.

Two services on Railway's private network. Django reads PGHOST, PGPORT, PGUSER, PGPASSWORD and PGDATABASE straight from the Postgres service.


About Hosting Django

Running Django in production means Gunicorn instead of runserver, a real database, migrations on every release, static files served efficiently, and secrets kept out of the code. Setting that up on a VPS is Nginx, systemd and a Postgres install to maintain.

On Railway, the start command runs python manage.py migrate, collects static files and launches Gunicorn, and WhiteNoise serves the static assets — no separate web server. Database credentials are injected automatically, and every push to your fork redeploys.

Harden it before launch. This starter keeps SECRET_KEY, DEBUG = True and ALLOWED_HOSTS = ["*"] in mysite/settings.py. Before real users arrive, read SECRET_KEY from an environment variable, set DEBUG to False and list your domain in ALLOWED_HOSTS and CSRF_TRUSTED_ORIGINS. The starter pins Django 5.0; upgrade to a supported release such as 5.2 LTS.

Typical cost: ~$3–8/month on Railway for the app and database. Heroku's Basic dyno is $7 plus $5 for Essential-0 Postgres, and Render's free Postgres expires after 30 days.


Deploy Django in Under 5 Minutes

  1. Click Deploy on Railway — Railway forks the code, builds Django and starts Postgres (~2–3 minutes).
  2. Open the public URL to see the app.
  3. Clone your repository and move SECRET_KEY and DEBUG into environment variables.
  4. Run python manage.py createsuperuser from the Railway CLI to use the admin panel.
  5. Push changes — migrations run automatically on each deploy.

No Nginx. No manual migrations. No database server to babysit.


Common Use Cases

  • Heroku alternative for Django — "deploy django with postgres" without dyno and add-on pricing
  • SaaS backends — models, auth and admin ready from day one
  • REST APIs — add Django REST Framework to the starter
  • Internal tools and dashboards — the Django admin as a back office
  • Content sites — pair with Wagtail or Django CMS
  • Teaching and prototypes — a live Django app with a real database in minutes

Configuration

VariableRequiredDescription
PGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE✅ Auto-injectedPostgres connection from the Postgres service.
PORTAuto-set8000, the port Gunicorn listens on.
DISABLE_COLLECTSTATICOptional1 — the start command collects static files instead of the build step.
SECRET_KEY, DEBUGRecommendedAdd these and read them in settings.py before going to production.

DEBUG = True leaks details. With debug on, error pages show settings and stack traces to anyone. Turn it off before you share the URL.


Django on Railway vs. Alternatives

Django on RailwayHerokuRenderPythonAnywhere-style shared hosts
Monthly cost (app + database)~$3–8 usage$7 Basic + $5 PostgresFree tier sleeps; paid from ~$7 + databaseVaries
Managed Postgres in the same project✅ Included✅ Add-on⚠️ Free DB expires in 30 days⚠️ Often MySQL or extra cost
Always-on app✅ Yes✅ On Basic⚠️ Free spins down✅ Yes
Migrations on deploy✅ Start command⚠️ Release phase setup⚠️ Manual setup❌ Manual
Deploy on git push✅ Yes✅ Yes✅ Yes❌ Usually manual
License✅ BSD-3 Django, starter code yours❌ Proprietary platform❌ Proprietary platform❌ Proprietary platform

Dependencies for Django Hosting

  • Railway account — Hobby ($5/month) covers a small app and database.
  • A GitHub account — Railway forks the starter so you own the code.

Deployment Dependencies

Implementation Details

The repository's start command runs python manage.py migrate && python manage.py collectstatic --noinput && gunicorn mysite.wsgi. WhiteNoise middleware serves static files from the app process, and psycopg2 connects to Postgres using the injected PG* variables.

Before production: move SECRET_KEY to an environment variable, set DEBUG = False, restrict ALLOWED_HOSTS and CSRF_TRUSTED_ORIGINS to your domain, and upgrade from Django 5.0 to a supported release.


Frequently Asked Questions

What does this Django template include? A Django project served by Gunicorn, a PostgreSQL database, WhiteNoise for static files, and a start command that runs migrations on every deploy.

How much does Django hosting cost compared to Heroku? About $3–8/month in Railway usage for the app and database. Heroku is $7 for a Basic dyno plus $5 for the smallest Postgres, $12/month before any growth.

Why do I get "DisallowedHost" or CSRF errors? Django only accepts requests for hosts in ALLOWED_HOSTS, and form posts need your domain in CSRF_TRUSTED_ORIGINS (with https://). Add your Railway or custom domain to both.

Do I lose data when I redeploy? No. Data lives in Postgres on a persistent volume. Uploaded media files in the app container are reset on deploy — use a volume or S3-compatible storage for them.

How do I create an admin user? Install the Railway CLI, link the project and run railway run python manage.py createsuperuser, then sign in at /admin.

Is this starter production-ready as is? Not yet: it keeps an insecure SECRET_KEY and DEBUG = True, and pins Django 5.0, which is past end of support. Move secrets to environment variables, turn debug off and upgrade before launch.


Why Deploy and Host Django on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Django on Railway, you get Gunicorn, PostgreSQL and automatic migrations on every push for a few dollars a month, with the code in your own repository.


Template Content

More templates in this category

View Template
open-excalidraw
Self-hostable collaborative drawing built on Excalidraw

Prateek Mohanty
5
View Template
NEW
Next.js + Prisma + PostgreSQL Starter
Deploy a Next.js app with Prisma ORM and PostgreSQL in one click.

blueorange
0
View Template
caring-vibrancy
Deploy and Host caring-vibrancy with Railway

5