Opened 9 years ago

Closed 3 years ago

Last modified 22 months ago

#4278 closed New feature (fixed)

get_template should accept a dirs argument

Reported by: amcnabb Owned by: Berker Peksag
Component: Template system Version: master
Severity: Normal Keywords: tplrf-patched
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The function django.template.loader.find_template_source already accepts a dirs argument, which makes it possible to override TEMPLATE_DIRS. However, get_template and other functions are not aware of find_template_source's dirs argument. The attached patch adds this dirs argument, with a default value of None, to a few additional functions.

After applying the patch, I can do:

render_to_response('some_template_file.html', dirs=(SOME_OTHER_DIRECTORY,))

Attachments (2)

loader.diff (2.0 KB) - added by anonymous 9 years ago.
template-dirs.diff (2.3 KB) - added by Adam Vandenberg 6 years ago.
Rebase on trunk.

Download all attachments as: .zip

Change History (18)

Changed 9 years ago by anonymous

Attachment: loader.diff added

comment:1 Changed 9 years ago by anonymous

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Summary: get_template should accept a dirs argument[patch] get_template should accept a dirs argument

comment:2 Changed 9 years ago by Simon G. <dev@…>

Summary: [patch] get_template should accept a dirs argumentget_template should accept a dirs argument
Triage Stage: UnreviewedDesign decision needed

Sounds like a fairly good idea.

comment:3 Changed 9 years ago by anonymous

This looks like a simple patch. Has anyone looked at it recently?

comment:4 Changed 8 years ago by Johannes Dollinger

Keywords: tplrf-fixed added

This would be fixed by #7815.

comment:5 Changed 8 years ago by Johannes Dollinger

Keywords: tplrf-patched added; tplrf-fixed removed

...

comment:6 Changed 6 years ago by Malcolm Tredinnick

Triage Stage: Design decision neededAccepted

Definitely a good idea in principle. The patch might well need refreshing, but the concept is sound.

Changed 6 years ago by Adam Vandenberg

Attachment: template-dirs.diff added

Rebase on trunk.

comment:7 Changed 6 years ago by Adam Vandenberg

Needs documentation: set
Needs tests: set

comment:8 Changed 5 years ago by Łukasz Rekucki

Severity: Normal
Type: New feature

comment:9 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:10 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:11 Changed 4 years ago by Berker Peksag

Owner: changed from nobody to Berker Peksag
Status: newassigned

comment:12 Changed 3 years ago by Berker Peksag

Needs documentation: unset
Needs tests: unset

I've opened a pull request on GitHub: https://github.com/django/django/pull/1632

comment:13 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 2f0566fa61e13277364e3aef338fa5c143f5a704:

Fixed #4278 -- Added a dirs parameter to a few functions to override TEMPLATE_DIRS.

  • django.template.loader.get_template()
  • django.template.loader.select_template()
  • django.shortcuts.render()
  • django.shortcuts.render_to_response()

Thanks amcnabb for the suggestion.

comment:14 Changed 2 years ago by Todd Reed

The new dirs parameters doesn't quite behave like I expected because dirs is only used to find the top level template. If the template has an include tag, it reverts to the template directories listed in TEMPLATE_DIRS and does not use the directories listed in dirs.

comment:15 Changed 2 years ago by Aymeric Augustin

I'm also finding the change weird.

For instance, when the dirs parameter is passed, the app_directories loader starts behaving like the filesystem template loader, while the eggs template loader ignores it entirely. It looks like this ticket doesn't account for template loaders other than filesystem.

comment:16 Changed 22 months ago by Aymeric Augustin <aymeric.augustin@…>

In 17012b6936128fb771b98e4fa6d78caddd07a9a8:

Deprecated dirs argument to override TEMPLATE_DIRS.

Cancels 2f0566fa. Refs #4278.

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