When building out apps with #HTMX, I end up with views and templates for both "pages" and (lots of) “partials”. Does anyone have any tips for organizing those two things?

It feels kind of messy in a way that having the strict boundary of a separate API doesn’t. (Although having a separate frontend framework just to client-side render HTML is messy in a whole other way)

Maybe just being more disciplined about routing and naming the partial templates would solve some of this…

Maybe this is overkill, but it's kind of what I'm thinking about

@adamghill have you ever used Django template partials from @carlton? I followed a pattern similar to you on the last project I worked on with HTMX, but since discovering DJTP, it’s what I’d start with in future I think.

https://github.com/carltongibson/django-template-partials

GitHub - carltongibson/django-template-partials: Reusable named inline partials for the Django Template Language.

Reusable named inline partials for the Django Template Language. - carltongibson/django-template-partials

GitHub
@mrchrisadams @carlton I have looked at it and... I don't understand how this would work. 😂 I probably just need to try it out and see how it goes.
Tips - django-htmx 1.26.0 documentation

@adamchainz @mrchrisadams @carlton ok, this example is helpful to me — sometimes I like to see some example code of how all the pieces fit together. Thank you!

@adamghill @adamchainz @mrchrisadams only thing I’d add there is that I use Neapolitan to keep the full and partial views grouped together. Often they’re reusing logic (to the extent of being identical bar the template name many times) so even if they have separate handlers I want them side by side in the file.

Seems to work nicely. Things need care and pruning and always, but I don’t think a file layout changes that.

@adamghill

This proliferation of endpoints is one of the reason #Datastar has been created, initially as a port of #HTMX ro Typescript + SSE, now it's the most hypermedia-oriented framework:

https://data-star.dev/

With SSE you can update portions of the web page from the server and with signals you can propagate changes client-side. With the former you can manage the state totally server-side, with the latter you can avoid involving the server when there aren't state changes.

Datastar

The hypermedia framework.

Datastar
@alxlg datastar looks super cool. I’m hopeful to try it out at some point!

@adamghill @alxlg I highly recommend it!

I'm planning on posting a blog post in the next couple of days showing why I have switched from HTMX to Datastar.

When I use Datastar, I think about rendering the whole component instead of trying to render partials, since they use an algorithm (I think ideomorph) to change what needs updating.

Some people also use a url query parameter or an http header to tell any route to not include the layout wrapper or similar.
@adamghill check out my article https://www.loopwerk.io/articles/2025/alpine-ajax-django/. It’s about Alpine AJAX but it’s exactly the same with htmx (just the header has a different name). Article has examples on how to integrate with template partials.
Beyond htmx: building modern Django apps with Alpine AJAX

Ditch the complex SPA. Learn how to build modern, server-rendered Django apps using Alpine AJAX and the power of hypermedia.

Loopwerk
@kevinrenskers This is great, thanks!