Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24111 closed Bug (wontfix)

get_template dirs parameter doesn't work for loading of parent template

Reported by: ThomasWaldmann Owned by: nobody
Component: Template system Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (2)

comment:1 by Aymeric Augustin, 10 years ago

Resolution: wontfix
Status: newclosed

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.

comment:2 by Aymeric Augustin, 10 years ago

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

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