django-jinja-render-block
This project aims to bring the super ergomomic partial template rendering of django-template-partials to django-jinja. It's a bit more limited in scope though: instead of allowing you to define reusable (inline) template partials using {% partialdef partial-name %}, it limits itself to rendering a block within a template, ala django-render-block.
TL;DR: you can render just a block using a template name such as template-name.jinja#block-name.
Installation
uv add django-jinja-render-block
Then use its template backend, instead of the one from django-ninja:
TEMPLATES = [
{
"BACKEND": "render_block.backend.Jinja2", # <- instead of "django_jinja.jinja2.Jinja2"
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
# ...
},
},
]
Usage
Define a block in your Jinja template:
{% extends "base.jinja" %}
{% block body %}
<h1>HOME</h1>
{% block test-partial %}
<p>Partial block content</p>
{% endblock %}
<p>Lorum ipsum</p>
{% endblock %}
And in your view code you use the template name plus the partial block name, like so:
class ExamplePartialView(TemplateView):
template_name = "example.jinja#test-partial"
This is extremely useful in combination with HTMX:
def example_view(request):
template_name = "example.jinja"
if request.htmx:
template_name += "#test-partial"
return TemplateResponse(request, template_name)
request.htmxcomes from django-htmx
Thanks to
- https://github.com/carltongibson/django-template-partials for the initial idea. I love the way it allows you to render a partial template just by appending the partial name to the template name. It only works with the Django Template Language though.
- https://github.com/clokep/django-render-block for showing me how to render a single block out of a template.
Release files for django-jinja-render-block 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_jinja_render_block-0.3.0.tar.gz | 8.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_jinja_render_block-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.9 kB
Release files / django_jinja_render_block-0.3.0.tar.gz
| Download URL | django_jinja_render_block-0.3.0.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
18adab8ca59bfcb366ac335d30159c238b44b4b1b146fa9d7d742df5c1e45971
|
|
BLAKE2b-256 checksum How to use checksums |
bfa65f0c1b70f44b919cea589dc523526f44b213568c3e88e1c078c8d1247796
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.13
|
Release files / django_jinja_render_block-0.3.0-py3-none-any.whl
| Download URL | django_jinja_render_block-0.3.0-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2190165c4aa5a341a67d87f1cf039902fcc8a982c5a9ed624385c97815ed86db
|
|
BLAKE2b-256 checksum How to use checksums |
dcf55f868aca7772b42252a08953ba2bc80d8352174590962f7cdb6ffd67dfd9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.13
|