Opened 17 years ago
Closed 11 years ago
#6834 closed New feature (wontfix)
Add support for templates to be loaded from dynamically-selected directories
Reported by: | durin42 <at> gmail.com | 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 |
Description
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)
Change History (14)
by , 17 years ago
Attachment: | loader_tags.diff added |
---|
comment:1 by , 17 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:2 by , 17 years ago
Needs tests: | set |
---|
comment:3 by , 16 years ago
Keywords: | tplrf-patched added |
---|
comment:4 by , 14 years ago
Triage Stage: | Design decision needed → Accepted |
---|
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 , 14 years ago
Type: | → New feature |
---|
comment:6 by , 14 years ago
Severity: | → Normal |
---|
comment:9 by , 11 years ago
Cc: | added |
---|---|
Patch needs improvement: | set |
comment:10 by , 11 years ago
Needs tests: | unset |
---|---|
Owner: | changed from | to
Patch needs improvement: | unset |
Status: | new → assigned |
I've opened a pull request on GitHub: https://github.com/django/django/pull/1702
comment:11 by , 11 years ago
Patch needs improvement: | set |
---|
There are some comments on the PR for improvement. I also have a couple more thoughts:
- 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.
- 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.
- I'd also like to see a test to ensure that directory traverse isn't possible.
- 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 , 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.
comment:13 by , 11 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
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.
Thanks!
This would be fixed by #7815.