Django, HTMX, and front-end scripting
As I’ve mentioned a few times, HTMX is really growing on me for building web things lately. When stacked on top of Django, it lets me mostly write server side code, which is my comfort zone, but get pages that load and behave the way people expect them to in 2022. It doesn’t free me from all need to write stuff that runs in the browser, though. Here’s what I’ve found useful lately.
I started off watching this excellent set of videos. It’s a great orientation toward how nicely HTMX plays with Django’s templates.
Benoit Blanchon’s articles and videos about modal forms and toasts also caught my eye. The way he uses empty responses is very interesting. And the demonstration of handling HTMX events is easy to pick out and instructive. I wound up adapting his approach to use TailwindCSS and Alpine because that matches up better with the things I tend to use. The modal works a little differently than it does with bootstrap. That may be worth its own post, but not today.
This article by Owen Jones shows the same approach using hyperscript with HTMX, and I really like it. I used to write a lot of HyperTalk in the early 1990s, and doing web things with hyperscript feels very much like the spiritual successor to that. I’m not sure that I’m ready to use it “in anger” yet. It hasn’t seen a release its author considers “stable”, it does require shipping a “runtime” down to the browser when you use it, and I’m concerned that it could be a challenge to hand an application that makes heavy use of hyperscript off to someone else for long term maintenance. But I’m really tempted in spite of those 3 reservations.
This link dump got longer than I wanted it to. I should probably delete the last paragraph but I won’t. The real point of this post is to throw links to the articles from Owen Jones and Benoit Blanchon, along with my demo project for doing similar things with Tailwind and Alpine, where I can easily find them and share them.
I’m trying on Kev Quirk’s “100 Days To Offload” idea. You can see details and join yourself by visiting 100daystooffload.com.
This is day 8.