Opened 14 years ago

Closed 14 years ago

#579 closed enhancement (invalid)

Split template_file template loading and template location logic

Reported by: Michael Twomey <micktwomey@…> Owned by: Adrian Holovaty
Component: Template system Version:
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


To make life a little easier for someone using a different templating system (e.g. kid), it'd useful to be able to use django's template location logic to traverse the template directories finding your custom template file.

I've created a patch which splits django.core.template_file.load_template_source into two functions, find_template (which locates a template somewhere in the template directories) and load_template_source which behaves exactly the same as before, except it uses find_template.

An example of it's use in a view:

from django.core import template_file

def blog_feed(request, ...):
    ...get objects...
    filename = template_file.find_template("custom_template.xml")
    renderer = my_custom_renderer(filename, ...)
    return HttpResponse(renderer.render(), mimetype="application/xml")

Attachments (1)

find_template.patch (1.4 KB) - added by Michael Twomey <micktwomey@…> 14 years ago.
svn diff of

Download all attachments as: .zip

Change History (4)

Changed 14 years ago by Michael Twomey <micktwomey@…>

Attachment: find_template.patch added

svn diff of

comment:1 Changed 14 years ago by Adrian Holovaty

Quick question: Why'd you change the try/except to an if statement? Personal preference, or is there a solid reason?

comment:2 Changed 14 years ago by Sune Kirkeby <sune.kirkeby@…>

Is this needed now that we have load_template_source? Also, it won't work easily for templates not stored as files (i.e. database-based templates and egg-templates), you would have to write the template-source out to a temporary file...

comment:3 Changed 14 years ago by rjwittams

Resolution: invalid
Status: newclosed

This doesn't really make much sense any more with the template loading changes.
Open a new ticket if load_template_source does not fit the bill.

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