Closed bbelderbos closed 9 months ago
For starters: add the library in your base.html:
You learn best from the examples, e.g. https://htmx.org/examples/active-search/
<input class="form-control" type="search"
name="search" placeholder="Begin Typing To Search Users..."
hx-post="/search"
hx-trigger="input changed delay:500ms, search"
hx-target="#search-results"
hx-indicator=".htmx-indicator">
Then in your html add directives like:
hx-post="/search"
This makes a post request to the search endpoint (Django view)
There you use the ORM to retrieve tunes and return html (not json) e.g.
In the hx-target
you specify the html element id where this resulting html gets inserted. Like JS this all happens on a loaded DOM, so no page reload is needed ("ajax")
FYI @ryaustin reading the book on this actually: https://hypermedia.systems
@jwjacobson so in your case I would envision something like:
matching_tunes_queryset
you have now in your tune_play
viewFYI @ryaustin reading the book on this actually: https://hypermedia.systems
Thanks for this reminder actually. I like Carson's approach to web. Fits well into my less complex style and htmx is perfect for minimizing complexity.
Basically @jwjacobson it works great to start to think of your webapp as an internal api (because that's what it is anyway right). You will setup endpoints to return specific chunks of data (Preshaped as in a table or not, maybe just a queryset). With HTMX you can target these endpoints and load them wherever you want on your page.
FYI @ryaustin reading the book on this actually: https://hypermedia.systems
Thanks for this reminder actually. I like Carson's approach to web. Fits well into my less complex style and htmx is perfect for minimizing complexity.
Yep we're finding this now with handling two forms in a view :)
It's a bit hard to learn from docs alone though, no?
So maybe good to watch Ryan + my code clinic sessions: https://pybites.circle.so/c/pybites-coaching-calls/sections/117462/lessons/394775 https://pybites.circle.so/c/pybites-coaching-calls/sections/117462/lessons/394695
pending work to be continued in https://github.com/jwjacobson/jazz_repertoire/issues/135
Writing up how to go about this ...
Check out the cool stuff you can do: https://htmx.org/examples/
There are also some nice code clinics we did ...