Opened 3 months ago

Closed 3 weeks ago

Last modified 2 weeks ago

#36410 closed New feature (fixed)

Add named template partials to the DTL.

Reported by: Carlton Gibson Owned by: Farhan Ali
Component: Template system Version: dev
Severity: Normal Keywords: partials
Cc: Carlton Gibson, Farhan Ali Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Completing the cycle begun in 2023, incorporate named template partials into the Django Template Language.

Starting with the forum discussion on Adding template fragments or partials for the DTL we added the internal structures necessary for template partials in #34883.

The third-party django-template-partials package, first released during the Django 4.2 cycle, has battle-tested the implementation over a full LTS cycle, and gained significant community uptake.

The project to merge this into Django was accepted for GSoC 2025, with Farhan Ali Raza implementing it.

The project is to merge to the two template tags, for defining and rendering a partial, plus the integration with template loader, so that partial fragments can be loaded by name. A migration guide will be added to the django-template-partials repo for existing users.

Change History (16)

comment:1 by Sarah Boyce, 3 months ago

Triage Stage: UnreviewedAccepted

comment:2 by Farhan Ali, 7 weeks ago

Cc: Farhan Ali added
Has patch: set

comment:3 by Natalia Bidart, 6 weeks ago

Needs tests: set
Patch needs improvement: set

comment:4 by Farhan Ali, 6 weeks ago

Needs tests: unset
Patch needs improvement: unset

There are a couple of comments remaining about code moving. But it is not clear what decision is made about those.

comment:5 by Natalia Bidart, 6 weeks ago

Patch needs improvement: set

comment:6 by Farhan Ali, 6 weeks ago

Patch needs improvement: unset

comment:7 by Natalia Bidart, 5 weeks ago

Patch needs improvement: set

comment:8 by Farhan Ali, 4 weeks ago

Patch needs improvement: unset

comment:9 by Natalia Bidart, 4 weeks ago

Needs tests: set
Patch needs improvement: set

comment:10 by Farhan Ali, 3 weeks ago

Patch needs improvement: unset

comment:11 by Farhan Ali, 3 weeks ago

Needs tests: unset

comment:12 by Natalia Bidart, 3 weeks ago

Patch needs improvement: set

comment:13 by Farhan Ali, 3 weeks ago

Patch needs improvement: unset

comment:14 by Natalia Bidart, 3 weeks ago

Triage Stage: AcceptedReady for checkin

comment:15 by nessita <124304+nessita@…>, 3 weeks ago

Resolution: fixed
Status: assignedclosed

In 5e06b970:

Fixed #36410 -- Added support for Template Partials to the Django Template Language.

Introduced {% partialdef %} and {% partial %} template tags to
define and render reusable named fragments within a template file.
Partials can also be accessed using the template_name#partial_name
syntax via get_template(), render(), {% include %}, and other
template-loading tools.

Adjusted get_template() behavior to support partial resolution, with
appropriate error handling for invalid names and edge cases. Introduced
PartialTemplate to encapsulate partial rendering behavior.

Includes tests and internal refactors to support partial context
binding, exception reporting, and tag validation.

Co-authored-by: Carlton Gibson <carlton@…>
Co-authored-by: Natalia <124304+nessita@…>
Co-authored-by: Nick Pope <nick@…>

comment:16 by Natalia Bidart, 2 weeks ago

Keywords: partials added
Note: See TracTickets for help on using tickets.
Back to Top