Skip to content

jsubroto/htmx-template-reload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

htmx-template-reload

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 --reload

Open 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 --reload

Tests:

uv run pytest -q

Notes:

  • Tiny dev helper, provided as-is with minimal support.
  • MIT licensed (see LICENSE).

About

Tiny dev helper for FastAPI + Jinja template auto-reload with HTMX.

Topics

Resources

License

Stars

Watchers

Forks

Contributors