4 ms·
How do you handle template and fragments? any libraries/usage patterns you use to integrate django <-> htmx?
by raihansaputra 4y ago
How do you handle template and fragments? any libraries/usage patterns you use to integrate django <-> htmx?
- neurostimulant 4y 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 4y agoAwesome, thank you!
- globular-toast 4y 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 4y 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.