Deploy HTMX+Python+Django+Postgres
HTMX + Python + Django + Postgres. Full-stack server-rendered starter.
Just deployed
/var/lib/postgresql/data
Just deployed
Deploy and Host HTMX+Python+Django+Postgres on Railway
HTMX+Python+Django+Postgres is a starter for hypermedia-driven UIs: Django renders HTML, HTMX swaps partial responses in the browser, and PostgreSQL stores data—no SPA and no separate Node build. The demo is a small Todo app with Gunicorn in production, DATABASE_URL via dj-database-url, and Tailwind + HTMX from a CDN.
About Hosting HTMX+Python+Django+Postgres
You ship a Dockerfile that installs dependencies, runs python manage.py migrate, and starts Gunicorn on 0.0.0.0:$PORT. Django reads DATABASE_URL (required); dj-database-url parses it and enables SSL for non-local hosts. URLs follow Django’s APPEND_SLASH convention—use GET /health/ (with trailing slash) for Railway health checks. CSRF is wired for POST/PATCH/DELETE from HTMX using {% csrf_token %} plus a small htmx:configRequest hook. Add the Postgres plugin, connect a web service from this repo, and set DATABASE_URL="${{Postgres.DATABASE_URL}}" on the web service (name must match your database service). Pushes to the linked branch trigger rebuilds; traffic from the app to Postgres stays on Railway’s private network.
Common Use Cases
- Internal CRUD and admin-style tools where server-rendered HTML and HTMX are enough, without React or Vue.
- Teaching or prototyping HTMX with a familiar Django stack, real migrations, and a production-shaped container.
- Small SaaS or team apps that need Postgres, forms, and partial-page updates with minimal JavaScript.
Dependencies for HTMX+Python+Django+Postgres Hosting
- A PostgreSQL instance and a
DATABASE_URLthe container can use at runtime. - A web service built from this repo’s Dockerfile (or equivalent) with
PORTsupplied by the platform.
Deployment Dependencies
Implementation Details
- Reference Postgres from the web service:
DATABASE_URL="${{Postgres.DATABASE_URL}}"(adjustPostgresto your service name). - Optional secret: set
DJANGO_SECRET_KEYin production; the repo avoids checking in secrets. - HTMX + CSRF (pattern used in templates): body carries
data-csrf, and the form includes the token soX-CSRFTokenis sent on non-GET requests.
Why Deploy HTMX+Python+Django+Postgres 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 HTMX+Python+Django+Postgres on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
PGDATA
data directory (volume); often set by the image
PGPORT
omit for default 5432, or set explicitly
POSTGRES_DB
DB created on first init (official image / plugin)
POSTGRES_USER
superuser name on first init
SSL_CERT_DAYS
optional TLS cert lifetime if you generate certs
RAILWAY_DEPLOYMENT_DRAINING_SECONDS
drain window during deploys