---
title: "Deploy HTMX + FastAPI + Jinja2 + Postgres"
description: "HTMX FastAPI + Jinja2 + Python + PostgreSQL. Async API + server templates."
category: "Starters"
url: https://railway.com/deploy/htmx-fastapi-jinja2-postgres
---

# Deploy HTMX + FastAPI + Jinja2 + Postgres

HTMX FastAPI + Jinja2 + Python + PostgreSQL. Async API + server templates.

**[Deploy HTMX + FastAPI + Jinja2 + Postgres on Railway](https://railway.com/template/htmx-fastapi-jinja2-postgres)**

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

## Template content

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

- **Source:** https://github.com/atoolz/railway-htmx-python-fastapi-jinja2-pg
- **Health check:** /health
- **Public domain:** Yes

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

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

## Documentation

# Deploy and Host HTMX FastAPI Jinja2 Postgres on Railway

HTMX FastAPI Jinja2 Postgres is a **Python** hypermedia stack: **HTMX** handles dynamic DOM updates, **FastAPI** serves routes and responses, **Jinja2** renders HTML with inheritance and partials, and **asyncpg** talks to **PostgreSQL** asynchronously. The bundled Todo app shows how to return HTML fragments for swaps while keeping logic and validation on the server.

## About Hosting HTMX FastAPI Jinja2 Postgres

Run the app as a **container** from the **Dockerfile** (Python slim base). **FastAPI** binds to **`PORT`** and reads **`DATABASE_URL`**. **asyncpg** provides an async pool; **migrations run at startup** to create tables. Templates live under **`templates/`** and return **`HTMLResponse`** for full pages or fragments for **HTMX**. CDN scripts cover **HTMX** and **Tailwind**—no separate frontend build. Connect Postgres over Railway’s **private network**; use **`GET /health`** for deploy checks (JSON + DB ping). This stack suits teams that want **async Python**, **OpenAPI** ergonomics from FastAPI, and **Jinja2** familiarity without adopting a SPA framework.

## Common Use Cases

- **Async** CRUD and forms with HTMX-driven partial updates.
- APIs that also serve **human-facing HTML** from the same FastAPI app.
- Onboarding developers who know **Python** and **Jinja2** already.

## Dependencies for HTMX FastAPI Jinja2 Postgres Hosting

- **Railway PostgreSQL** provisioned for the project.
- **`DATABASE_URL`** on the FastAPI service (e.g. `${{Postgres.DATABASE_URL}}`).

### Deployment Dependencies

- [HTMX documentation](https://htmx.org/docs/)
- [FastAPI](https://fastapi.tiangolo.com/)
- [Jinja2](https://jinja.palletsprojects.com/)
- [asyncpg](https://github.com/MagicStack/asyncpg)

### Implementation Details

- Health: `GET /health` in `main.py` — JSON; DB error → 503.
- Templates: `templates/*.html` with HTMX attributes on partials.

## Why Deploy HTMX FastAPI Jinja2 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 FastAPI Jinja2 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

- [Paperless-ngx](https://railway.com/deploy/paperless-ngx-3) — Document management with OCR on Railway with PostgreSQL and Redis
- [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

Open this page in a browser: https://railway.com/deploy/htmx-fastapi-jinja2-postgres
