Opened 19 years ago
Closed 19 years ago
#579 closed enhancement (invalid)
Split template_file template loading and template location logic
Reported by: | 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 |
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)
Change History (4)
by , 19 years ago
Attachment: | find_template.patch added |
---|
comment:1 by , 19 years ago
Quick question: Why'd you change the try
/except
to an if
statement? Personal preference, or is there a solid reason?
comment:2 by , 19 years ago
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 by , 19 years ago
Resolution: | → invalid |
---|---|
Status: | new → 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.
svn diff of template_file.py