Take inspiration from FastHTML to make implementing HTMX easier #11966
-
First Check
Commit to Help
Example Codefrom fasthtml.common import *
app,rt = fast_app()
@rt('/')
def get(): return Div(P('Hello World!'), hx_get="/change")
serve()DescriptionI’ve been loving the experience working with FastHTML lately to create fully interactive apps using only Python, with the help of HTMX for the interactive bits. When it’s time to make a serious API, though, FastAPI is much better, and in fact the FastHTML docs encourage its use:
However, incorporating HTMX into a FastAPI app isn’t as nice an experience. You have to render jinja templates for html files (see this tutorial or a couple of the other questions asked in this discussion forum when you search for “HTMX”). This is much more complicated than simply returning HTML directly using FastHTML’s so-called ft components, eg from fasthtml.common import *
app,rt = fast_app()
@rt('/')
def get(): return Div(P('Hello World!'), hx_get="/change")What does the community think about offering functionality similar to FastHTML’s ft components to make it easier to turn Python objects into HTML and return that rendered html with HTMX requests? Operating SystemLinux Operating System DetailsNo response FastAPI Versionn/a Pydantic Versionn/a Python Versionn/a Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
|
I think you can already achieve this by mounting a |
Beta Was this translation helpful? Give feedback.
-
|
Since today I'm trying out FastHX: That integrates HTMX into FastAPI with Jinja. |
Beta Was this translation helpful? Give feedback.
-
|
You can also use htpy https://htpy.dev/ or seamless https://github.com/xpodev/seamless which are similar to the ft components of FastHTML. I like FastHTML's implementation of the ft components. I think they use fastcore https://github.com/fastai/fastcore (same guys basically that did FastHTML). |
Beta Was this translation helpful? Give feedback.
I think you can already achieve this by mounting a
FastHTMLapp as a sub-app (https://fastapi.tiangolo.com/advanced/sub-applications/#sub-application) or vice-versa and then using the FastHTML functionality as you normally would.