Opened 8 years ago

Closed 23 months ago

Last modified 8 months ago

#4278 closed New feature (fixed)

get_template should accept a dirs argument

Reported by: amcnabb Owned by: berkerpeksag
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 8 years ago.
template-dirs.diff (2.3 KB) - added by adamv 5 years ago.
Rebase on trunk.

Download all attachments as: .zip

Change History (18)

Changed 8 years ago by anonymous

comment:1 Changed 8 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from get_template should accept a dirs argument to [patch] get_template should accept a dirs argument

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

  • Summary changed from [patch] get_template should accept a dirs argument to get_template should accept a dirs argument
  • Triage Stage changed from Unreviewed to Design decision needed

Sounds like a fairly good idea.

comment:3 Changed 8 years ago by anonymous

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

comment:4 Changed 7 years ago by emulbreh

  • Keywords tplrf-fixed added

This would be fixed by #7815.

comment:5 Changed 7 years ago by emulbreh

  • Keywords tplrf-patched added; tplrf-fixed removed

...

comment:6 Changed 5 years ago by mtredinnick

  • Triage Stage changed from Design decision needed to Accepted

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

Changed 5 years ago by adamv

Rebase on trunk.

comment:7 Changed 5 years ago by adamv

  • Needs documentation set
  • Needs tests set

comment:8 Changed 4 years ago by lrekucki

  • Severity set to Normal
  • Type set to New feature

comment:9 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:10 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:11 Changed 2 years ago by berkerpeksag

  • Owner changed from nobody to berkerpeksag
  • Status changed from new to assigned

comment:12 Changed 23 months ago by berkerpeksag

  • Needs documentation unset
  • Needs tests unset

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

comment:13 Changed 23 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

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 12 months ago by toddreed

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 11 months ago by aaugustin

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 8 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