partial Tag

Utility Most Useful

Argument(s): partial_name

Added in Django 6.0

Documentation

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 partial tag works hand-in-hand with partialdef. Together, they provide a clean way to define and reuse template fragments without creating separate template files.

This is especially useful for:

  • Repeating UI components (buttons, cards, list items) within a single template
  • Reducing duplication when the same markup appears multiple times
  • Keeping related template code together instead of splitting into many small files

For more details and examples, see the partialdef documentation.


Did we get something wrong? Is there a use case for the partial tag that we should add? Please let us know.

Send Feedback

Official Documentation
This page last updated on Dec. 3, 2025, 11:37 p.m. EST