Ticket #579: find_template.patch
File find_template.patch, 1.4 KB (added by , 19 years ago) |
---|
-
django/core/template_file.py
4 4 from django.core.template import TemplateDoesNotExist 5 5 import os 6 6 7 def load_template_source(template_name, template_dirs=None): 7 def find_template(template_name, template_dirs=None): 8 """Locates the template file in the template directories""" 8 9 if not template_dirs: 9 10 template_dirs = TEMPLATE_DIRS 10 11 tried = [] 11 12 for template_dir in template_dirs: 12 filepath = os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION13 try:14 return open(filepath).read()15 e xcept IOError:13 filepath = os.path.join(template_dir, template_name) 14 if os.path.isfile(filepath): 15 return filepath 16 else: 16 17 tried.append(filepath) 17 18 if template_dirs: 18 19 error_msg = "Tried %s" % tried 19 20 else: 20 21 error_msg = "Your TEMPLATE_DIRS settings is empty. Change it to point to at least one template directory." 21 22 raise TemplateDoesNotExist, error_msg 23 24 25 def load_template_source(template_name, template_dirs=None): 26 """Finds and opens the requested template, returning its contents""" 27 filepath = find_template(template_name + TEMPLATE_FILE_EXTENSION, template_dirs) 28 return open(filepath).read()