Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've only used HTMX for a tiny project along with FastAPI, it was basically just a single form page that would send the response in JSON to the server.

Things I liked were that it felt really lightweight, easy to setup, and basically just worked how the docs described.

However one thing I'm still trying to wrap my head around is how to better handle "intermediate" pieces of HTML i.e. partials. In SPAs you create a component that renders the template on the fly and is reused, but in HTMX you would need to hit an endpoint to get something like a partial.

This sort of had me pause because I'm so used to keeping my backend routes very "RESTy" (in the loose sense). But when using HTMX I was wondering if I need to make some routes like `/contact-form/modal` just to retrieve something like a success modal.

The article kinda displays what I mean with how all of the book routes return the buttons for the form. Also the `/get-book-row/<int:id>` and `/update/<int:id>` routes both return the same type of buttons. Those buttons seem prime candidates to be extracted into a common template of sorts.

Does that make sense? If so does anyone have a good example of a larger HTMX app which handles these scenarios?



Recently saw Michael Kennedy's presentation at Python Web Conference where he talks about this. He also has a course on using Flask + HTMX. Even if you don't take the course, you do have access to the github repo for that course.

https://github.com/talkpython/htmx-python-course

He wrote a small library extending Jinja that does what you're referencing here, I believe. It's a little different than Jinja macros and include (you can reference the github issues for a discussion on that).

https://github.com/mikeckennedy/jinja_partials

Maybe that's what you're looking for?


This is great, thanks!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: