Ticket #583: apploader.py

File apploader.py, 889 bytes (added by hugo, 19 years ago)

template loader that looks into app directories

Line 
1# Wrapper for loading templates from eggs via pkg_resources.resource_string.
2
3import os
4
5from django.conf.settings import INSTALLED_APPS
6from django.core.template import TemplateDoesNotExist
7
8def load_template_source(name, dirs=None):
9 """
10 This searches the application directories for a given
11 template. It looks into "templates" subdirectories of
12 any installed applications.
13 """
14 for app in INSTALLED_APPS:
15 i = app.rfind('.')
16 m, a = app[:i], app[i+1:]
17 m = getattr(__import__(m, globals(), locals(), [a]), a)
18 app_root = os.path.dirname(m.__file__)
19 td = os.path.join(app_root, 'templates')
20 if os.path.isdir(td):
21 tn = os.path.join(tn, '%s.html' % name)
22 if os.path.exist(tn):
23 return open(tn).read()
24 raise TemplateDoesNotExist, name
25
26load_template_source.is_usable = True
Back to Top