---
title: "Deploy HTMX+Python+Django+Postgres"
description: "HTMX + Python + Django + Postgres. Full-stack server-rendered starter."
category: "Starters"
url: https://railway.com/deploy/htmxpythondjangopostgres
---

# Deploy HTMX+Python+Django+Postgres

HTMX + Python + Django + Postgres. Full-stack server-rendered starter.

**[Deploy HTMX+Python+Django+Postgres on Railway](https://railway.com/template/htmxpythondjangopostgres)**

- **Creator:** André Ahlert
- **Category:** Starters

## Template content

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:18

### web https://raw.githubusercontent.com/atoolz/railway-htmx-python-django-pg/master/assets/icon.svg

- **Source:** https://github.com/atoolz/railway-htmx-python-django-pg
- **Health check:** /health

## Documentation

# 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_URL`** the container can use at runtime.
- A **web** service built from this repo’s **Dockerfile** (or equivalent) with **`PORT`** supplied by the platform.

### Deployment Dependencies

- [HTMX documentation](https://htmx.org/docs/)
- [Django documentation](https://docs.djangoproject.com/)
- [dj-database-url](https://github.com/jazzband/dj-database-url)
- [Gunicorn](https://docs.gunicorn.org/)
- [Railway documentation](https://docs.railway.com/)

### Implementation Details

- **Reference Postgres from the web service:** `DATABASE_URL="${{Postgres.DATABASE_URL}}"` (adjust **`Postgres`** to your service name).
- **Optional secret:** set **`DJANGO_SECRET_KEY`** in production; the repo avoids checking in secrets.
- **HTMX + CSRF (pattern used in templates):** body carries **`data-csrf`**, and the form includes the token so **`X-CSRFToken`** is 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.

## Similar templates

- [open-excalidraw](https://railway.com/deploy/open-excalidraw) — Self-hostable collaborative drawing built on Excalidraw
- [caring-vibrancy](https://railway.com/deploy/caring-vibrancy) — Deploy and Host caring-vibrancy with Railway
- [Appsmith](https://railway.com/deploy/appsmith-1) — Low-code platform for internal tools, dashboards, and admin panels.

Open this page in a browser: https://railway.com/deploy/htmxpythondjangopostgres
