Published django-block-fragments

Hello everyone! Yesterday I published the first release of django-block-fragments on PyPI. It is an alternative to the wonderful django-template-partials by Carlton Gibson and django-render-block by Patrick Cloke (and also uses many code fragments of both projects).

The idea is to render only the content of a specific block of a Django template. This is especially useful when using Django with libraries like HTMX, see Template Fragments.

You may wonder what distinguishes django-block-fragments from django-template-partials or django-render-block. In contrast to the more powerful django-template-partials it reuses the already existing block template tag (in contrast to some custom partialdef and partial template tag). You also don’t have to specify the block as inline as it always is. And in comparison to django-render-block it uses the convenience of template loaders. So you can render a “content” block for example by calling render(request, "template.html#content", {}) or using {% include "template.html#content" %} inside a template.

It’s still an early release, and I am happy to receive feedback, comments, or reported issues. I hope this library proves helpful to others.

3 Likes

This looks really useful, especially for HTMX users! Being able to render specific template blocks so easily is a great feature. I’ll definitely check it out.

Thanks for sharing, and congrats on the first release!

1 Like