Opened 17 years ago

Closed 11 years ago

Last modified 10 years ago

#4278 closed New feature (fixed)

get_template should accept a dirs argument

Reported by: amcnabb Owned by: Berker Peksag
Component: Template system Version: dev
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


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 17 years ago.
template-dirs.diff (2.3 KB ) - added by Adam Vandenberg 14 years ago.
Rebase on trunk.

Download all attachments as: .zip

Change History (18)

by anonymous, 17 years ago

Attachment: loader.diff added

comment:1 by anonymous, 17 years ago

Summary: get_template should accept a dirs argument[patch] get_template should accept a dirs argument

comment:2 by Simon G. <dev@…>, 17 years ago

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 by anonymous, 17 years ago

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

comment:4 by Johannes Dollinger, 16 years ago

Keywords: tplrf-fixed added

This would be fixed by #7815.

comment:5 by Johannes Dollinger, 16 years ago

Keywords: tplrf-patched added; tplrf-fixed removed


comment:6 by Malcolm Tredinnick, 14 years ago

Triage Stage: Design decision neededAccepted

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

by Adam Vandenberg, 14 years ago

Attachment: template-dirs.diff added

Rebase on trunk.

comment:7 by Adam Vandenberg, 14 years ago

Needs documentation: set
Needs tests: set

comment:8 by Łukasz Rekucki, 13 years ago

Severity: Normal
Type: New feature

comment:9 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:10 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:11 by Berker Peksag, 11 years ago

Owner: changed from nobody to Berker Peksag
Status: newassigned

comment:12 by Berker Peksag, 11 years ago

Needs documentation: unset
Needs tests: unset

I've opened a pull request on GitHub:

comment:13 by Tim Graham <timograham@…>, 11 years ago

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 by Todd Reed, 10 years ago

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 by Aymeric Augustin, 10 years ago

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 by Aymeric Augustin <aymeric.augustin@…>, 10 years ago

In 17012b6936128fb771b98e4fa6d78caddd07a9a8:

Deprecated dirs argument to override TEMPLATE_DIRS.

Cancels 2f0566fa. Refs #4278.

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