Railway

Deploy HTMX+Python+Django+Postgres

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

Deploy HTMX+Python+Django+Postgres

/var/lib/postgresql/data

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

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.


Template Content

More templates in this category

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

baleocho
View Template
Flask WebSocket Chat
Single file, realtime multi-user websocket chat using flask-socketio

Clement Ochieng
View Template
all-star-fashion-template
Deploy and Host all-star-fashion-template with Railway

Mai Thành Duy An