Our great sponsors
-
shoelace-css
A collection of professionally designed, every day UI components built on Web standards. SHOELACE IS BECOMING WEB AWESOME. WE ARE LIVE ON KICKSTARTER! 👇👇👇
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
htmx-python-course
Student details, source code, and more for our HTMX + Flask: Modern Python Web Apps, Hold the JavaScript course.
-
jinja_partials
Simple reuse of partial HTML page templates in the Jinja template language for Python web frameworks. #pypackage
I've been wanting to do this switch too and have the same concern. One option worth investigating is Shoelace - https://shoelace.style/, a library of nice looking web components that you can just add to your page without setting up a whole build pipeline.
I had the same pain points with Flask, so I built Flask Unchained to integrate many of the best extensions (IMO) to all work together out of the box in a reusable way:
https://github.com/briancappello/flask-unchained
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?
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?
If you use django-htmx, it's pretty simple to get the "this HTTP request came from HTMX" flag and branch accordingly in your view. The docs give a simple example of the logic here:
https://django-htmx.readthedocs.io/en/latest/middleware.html...
The examples give a fleshed-out version: https://github.com/adamchainz/django-htmx/blob/main/example/...
Though that's very slightly different than how I described it above, but it's basically the same idea; in this case you commonize the `main` block between the two contexts.
I was going by Github language stats indicating 90% HTML / 10% JS https://github.com/alpinejs/alpine