Tiny dev helper for FastAPI + Jinja template auto-reload with HTMX.
This is a tiny dev helper that reloads the browser when HTML templates change.
HTMX does not ship a built-in template autoreload, so this uses a WebSocket
plus watchfiles to broadcast a reload to connected clients. If the Python
server restarts, the socket closes and the page reloads too.
Why this exists: HTMX doesn't ship template auto-reload, and this shows a minimal FastAPI + Jinja setup to add it.
Run (one command for Python + template reload):
uv run fastapi run main.py --reloadOpen http://localhost:8000/ and edit templates/index.html to see the page
auto-refresh. Editing Python files will restart the server.
The reload script lives at statics/dev-reload.js and is included only when
DEV=1. Set DEV=0 to disable it.
Alternate run command:
uv run uvicorn main:app --reloadTests:
uv run pytest -qNotes:
- Tiny dev helper, provided as-is with minimal support.
- MIT licensed (see LICENSE).