[Django] #24111: get_template dirs parameter doesn't work for loading of parent template

11 views
Skip to first unread message

Django

unread,
Jan 9, 2015, 6:07:07 PM1/9/15
to django-...@googlegroups.com
#24111: get_template dirs parameter doesn't work for loading of parent template
---------------------------------+--------------------
Reporter: ThomasWaldmann | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------
Given: a directory "templates" with templates "something.txt" and
"base.txt" (and something.txt extends base.txt) and this code:
{{{
def render_template(template, context):
this_dir = os.path.abspath(os.path.dirname(__file__))
template_dir = os.path.join(this_dir, 'templates')
t = loader.get_template(template, dirs=[template_dir, ])
return t.render(Context(context))

# finds and renders base.txt:
render_template("base.txt")

# finds and tries to render something.txt, but then fails to find
base.txt:
render_template("something.txt")
}}}
I wanted to use this for django management commands which send emails, so
I just wanted to load templates from a specific directory.

--
Ticket URL: <https://code.djangoproject.com/ticket/24111>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 10, 2015, 2:57:17 AM1/10/15
to django-...@googlegroups.com
#24111: get_template dirs parameter doesn't work for loading of parent template
---------------------------------+--------------------------------------
Reporter: ThomasWaldmann | Owner: nobody
Type: Bug | Status: closed

Component: Template system | Version: 1.7
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by aaugustin):

* status: new => closed
* needs_better_patch: => 0
* resolution: => wontfix
* needs_tests: => 0
* needs_docs: => 0


Comment:

Yes, the `dirs` args doesn't work correctly with template inheritance and
was deprecated in Django 1.8 for this reason (among others).

This is a structural problem. Django loads templates with template loaders
and `dirs` only affects a small and incomplete part of loaders.

--
Ticket URL: <https://code.djangoproject.com/ticket/24111#comment:1>

Django

unread,
Jan 10, 2015, 2:58:16 AM1/10/15
to django-...@googlegroups.com
#24111: get_template dirs parameter doesn't work for loading of parent template
---------------------------------+--------------------------------------
Reporter: ThomasWaldmann | Owner: nobody
Type: Bug | Status: closed

Component: Template system | Version: 1.7
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by aaugustin):

In Django 1.8 you will be able to configure two templates engines, one for
general use and one for loading email templates :-)

--
Ticket URL: <https://code.djangoproject.com/ticket/24111#comment:2>

Reply all
Reply to author
Forward
0 new messages