django-template-partials

raw JSON →
25.3 verified Mon Apr 27 auth: no python

Reusable named inline-partials for the Django Template Language. Current version 25.3. Active development.

pip install django-template-partials
error 'template_partials' is not a registered tag library. Must be one of: ...
cause Missing the app in INSTALLED_APPS.
fix
Add 'template_partials' to INSTALLED_APPS in settings.py.
error TemplateSyntaxError: 'partial' tag requires exactly one argument (the partial name)
cause Calling {% partial %} without a name (or with `as` variable) in newer versions.
fix
Use {% partial my_partial %} with the exact partial name defined earlier.
error TemplateDoesNotExist: ... no idea why partials not rendering
cause Partials are only available in the same template where defined, or in included templates that reload the tag library.
fix
Ensure {% load partials %} is present in every template that uses partials.
breaking Breaking change in 24.2: the partial name is now required ({% partial name %} instead of optional).
fix Always provide a name for {% partial %} tags.
deprecated In 24.3, the `as` keyword for calling partials is deprecated; use the partial directly via `{% partial my_partial %}` instead of `{% partial my_partial as var %}`.
fix Remove `as var` from partial calls.
gotcha Partials are not available in included templates unless you reload the tag library; you must call {% load partials %} again in the included template.
fix Add {% load partials %} in each template where partials are used.

Add 'template_partials' to INSTALLED_APPS, then use {% load partials %} and {% partial %} / {% endpartial %} in templates.

# settings.py
INSTALLED_APPS = [
    ...
    'template_partials',
]

# template.html (load the tag)
{% load partials %}

{% partial my_partial %}
<p>Hello, {{ name }}!</p>
{% endpartial %}

{% partial my_partial %}
<!-- rendered inline -->