Code

Opened 9 years ago

Closed 9 years ago

#579 closed enhancement (invalid)

Split template_file template loading and template location logic

Reported by: Michael Twomey <micktwomey@…> Owned by: adrian
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: UI/UX:

Description

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@…> 9 years ago.
svn diff of template_file.py

Download all attachments as: .zip

Change History (4)

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

svn diff of template_file.py

comment:1 Changed 9 years ago by adrian

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

comment:2 Changed 9 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 9 years ago by rjwittams

  • Resolution set to invalid
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.