Opened 6 years ago

Closed 4 years ago

#13984 closed New feature (duplicate)

template.loader.select_template should return template_name as well.

Reported by: Daniel Duan Owned by: Josh Stegmaier
Component: Template system Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The whole purpose of this function is to find out which possible location of a certain template is valid. It make sense to return the compiled template as well as its location.

Here's a common use case:

A template is found by select_template, however, this template extends an "base.html" whose is located in the same directory, which is unknown until runtime as well. So the extends tag fails.

If select_template returns the location of the template it finds, then this info could be passed into an context and thus make the extends tag useful again.

Attachments (2)

0001-Added-template_name-as-a-return-value-of-django.temp.patch (1.7 KB) - added by Daniel Duan 6 years ago.
Added template_name as an return value to select_template
0002-template_name-as-optional-return-value-of-django.temp.diff (1.8 KB) - added by Josh Stegmaier 6 years ago.
Adds option to return template name with select_template and documents change.

Download all attachments as: .zip

Change History (9)

Changed 6 years ago by Daniel Duan

Added template_name as an return value to select_template

comment:1 Changed 6 years ago by Daniel Duan

Summary: template.select_template should return template_name as well.template.loader.select_template should return template_name as well.

The whole purpose of this function is to find out which possible location of a certain template is valid. It make sense to return the compiled template as well as its location.

Here's a common use case:

A template is found by select_template, however, this template extends an "base.html" whose is located in the same directory, which is unknown until runtime as well. So the extends tag fails.

If select_template returns the location of the template it finds, then this info could be passed into an context and thus make the extends tag useful again.

Changed 6 years ago by Josh Stegmaier

Adds option to return template name with select_template and documents change.

comment:2 Changed 6 years ago by Josh Stegmaier

Owner: changed from nobody to Josh Stegmaier
Status: newassigned

In order to maintain backwards compatibility, it would probably be better if returning the template name was optional. I've attached a patch that would accomplish this.

comment:3 Changed 6 years ago by Josh Stegmaier

Triage Stage: UnreviewedDesign decision needed

comment:4 Changed 6 years ago by Graham King

Severity: Normal
Type: New feature

comment:5 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:6 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:7 Changed 4 years ago by Aymeric Augustin

Resolution: duplicate
Status: assignedclosed

The pattern used to change the result type isn't elegant...

It seems to me that #16096 provides the same information with a better API.

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