Opened 16 years ago

Closed 10 years ago

#6834 closed New feature (wontfix)

Add support for templates to be loaded from dynamically-selected directories

Reported by: durin42 <at> Owned by: Berker Peksag
Component: Template system Version: dev
Severity: Normal Keywords: tplrf-patched
Cc: berker.peksag@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


For an app we're building with Django, it's become a requirement to be able to vary the template load directories based on the request information we get from the user, including the directories read by the extends and includes TemplateTags. The attached patch, along with the one on #4278 gives us all the functionality we need.

Attachments (1)

loader_tags.diff (5.2 KB ) - added by durin42 16 years ago.

Download all attachments as: .zip

Change History (14)

by durin42, 16 years ago

Attachment: loader_tags.diff added

comment:1 by anonymous, 16 years ago

Triage Stage: UnreviewedDesign decision needed

comment:2 by anonymous, 16 years ago

Needs tests: set

comment:3 by Johannes Dollinger, 16 years ago

Keywords: tplrf-patched added

This would be fixed by #7815.

comment:4 by Malcolm Tredinnick, 14 years ago

Triage Stage: Design decision neededAccepted

Without evaluating the patch, the concept is sound. So we'll take a good implementation of this (which might be this patch, refreshed to Django 1.2 -- I haven't looked at it).

comment:5 by Julien Phalip, 13 years ago

Type: New feature

comment:6 by Julien Phalip, 13 years ago

Severity: Normal

comment:7 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:8 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:9 by Berker Peksag, 11 years ago

Cc: berker.peksag@… added
Patch needs improvement: set

comment:10 by Berker Peksag, 11 years ago

Needs tests: unset
Owner: changed from nobody to Berker Peksag
Patch needs improvement: unset
Status: newassigned

I've opened a pull request on GitHub:

comment:11 by Tim Graham, 11 years ago

Patch needs improvement: set

There are some comments on the PR for improvement. I also have a couple more thoughts:

  1. I'm not super enthusiastic about this feature, perhaps partly because the use case is a bit vague -- I'd like to hear more about apps that allow choosing template directories based on user inputs.
  1. Do you know if Jinja2 offers a feature like this? I ask because there has been some talk of switching Django to use Jinja2 rather than using our own template language.
  1. I'd also like to see a test to ensure that directory traverse isn't possible.
  1. The current implementation doesn't seem ideal as it forces the context variable to be called dirs (am I reading that correctly?). Thus, if I have two {% include %} tags and want different directories for each of them, I'd have to jump through some hoops to make that work (like {% with dirs1 as dirs %}{% include "foo.html" dirs %}{% endwith %}) ...

comment:12 by Aymeric Augustin, 11 years ago

This patch breaks the TEMPLATE_LOADERS abstraction: it's adding in the template language a feature that alters the template loading behavior, but only works with Django's filesystem template loader — not the app directories template loader, for instance.

This ticket may predate the introduction of TEMPLATE_LOADERS. In my opinion it should be closed as wontfix, and the reporter should write a custom template loader. It's going to be a bit difficult to pass the request to the template loader; it may require a global (thread-local) variable or hooking on a signal.

Last edited 11 years ago by Aymeric Augustin (previous) (diff)

comment:13 by Berker Peksag, 10 years ago

Resolution: wontfix
Status: assignedclosed

Sorry for my *very* late response. I agree with both of you.

Do you know if Jinja2 offers a feature like this? I ask because there has been some talk of switching Django to use Jinja2 rather than using our own template language.

No, Jinja2 has no feature like that, but it is pretty much unmaintained these days.

Closing the ticket as won't fix.


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