Renders a template fragment that was previously defined with the partialdef tag.
New in Django 6.0.
Arguments
partial_name(required) – The name of the template fragment to render.
Template
{# First, define the partial #}
{% partialdef button %}
<button class="btn btn-{{ style }}">{{ label }}</button>
{% endpartialdef %}
{# Then render it multiple times #}
{% with style="primary" label="Save" %}
{% partial button %}
{% endwith %}
{% with style="secondary" label="Cancel" %}
{% partial button %}
{% endwith %}
{% with style="danger" label="Delete" %}
{% partial button %}
{% endwith %}
Result
<button class="btn btn-primary">Save</button> <button class="btn btn-secondary">Cancel</button> <button class="btn btn-danger">Delete</button>
Using Partials in Loops
Partials work well within loops, using the current context for each iteration:
Template
{% partialdef item-row %}
<tr>
<td>{{ item.name }}</td>
<td>{{ item.price }}</td>
</tr>
{% endpartialdef %}
<table>
{% for item in items %}
{% partial item-row %}
{% endfor %}
</table>

Commentary
The
partialtag works hand-in-hand withpartialdef. Together, they provide a clean way to define and reuse template fragments without creating separate template files.This is especially useful for:
For more details and examples, see the
partialdefdocumentation.