3 ms·
It’s Django.. request data in, html response out. That’s all what you need :)
by jonathan-adly 3y ago
It’s Django.. request data in, html response out. That’s all what you need :)
- powersnail 3y agoI'm asking because I've sort of done this in the past, and find creating fragments of HTML with Django's template engine a bit awkward. For instance, if I have some sort of utility button, and say I put it in "utility_button.html", a template file. In practice, I might have to supply different actions, or icon names, or colors when the button is generated, which means that each of these potential variable needs to be a template parameter. Adding a class involves some string manipulation magic. On the other hand, on most client-side front end library, when using a template, I can still slap whatever attributes onto the element, or manipulate its classes as an actual list with relative ease, because front end libraries are more or less already a big HTML parser and generator.
- raihansaputra 3y agoHow do you handle template and fragments? any libraries/usage patterns you use to integrate django <-> htmx?
- neurostimulant 3y agoIf you're lazy, just develop your django app as usual, and use hx-select attribute to select relevant content to use in htmx. Django doesn't have to be aware of the fact that you're using htmx in the client side. https://htmx.org/attributes/hx-select/ https://htmx.org/attributes/hx-select/
- TigerTeamX 3y agoAwesome, thank you!
- globular-toast 3y agoWhy would it need anything special? Django doesn't care what templates contain. You can have a template with literally anything in it, including HTML fragments.
- Dauros 3y agoUsually we have a base template with a content block that a child template can extend. The extend keyword supports variables as well. So we can create a dummy base template, e.g. fragment_base.html, that contains only the content block and if a request is coming from HTMX we set the base template to the dummy one, so the rendered template will contain only the fragment.