Ticket #6691: templateloader.diff
File templateloader.diff, 2.8 KB (added by , 17 years ago) |
---|
-
django/template/loader_tags.py
1 1 from django.template import TemplateSyntaxError, TemplateDoesNotExist, Variable 2 2 from django.template import Library, Node, TextNode 3 from django.template.loader import get_template, get_template_from_string, find_template_source3 from django.template.loader import get_template, find_template 4 4 from django.conf import settings 5 5 from django.utils.safestring import mark_safe 6 6 … … 61 61 if hasattr(parent, 'render'): 62 62 return parent # parent is a Template object 63 63 try: 64 source, origin = find_template_source(parent, self.template_dirs)64 template = find_template(parent, self.template_dirs) 65 65 except TemplateDoesNotExist: 66 66 raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent 67 67 else: 68 return get_template_from_string(source, origin, parent)68 return template 69 69 70 70 def render(self, context): 71 71 compiled_parent = self.get_parent(context) -
django/template/loader.py
40 40 else: 41 41 return None 42 42 43 def find_template _source(name, dirs=None):43 def find_template(name, dirs=None): 44 44 # Calculate template_source_loaders the first time the function is executed 45 45 # because putting this logic in the module-level namespace may cause 46 46 # circular import errors. See Django ticket #1292. … … 65 65 template_source_loaders.append(func) 66 66 for loader in template_source_loaders: 67 67 try: 68 source, display_name = loader(name, dirs) 69 return (source, make_origin(display_name, loader, name, dirs)) 68 template = loader(name, dirs) 69 70 try: 71 template, display_name = template 72 origin = make_origin(display_name, loader, name, dirs) 73 template = Template(template, origin, name) 74 except TypeError: 75 pass 76 77 return template 70 78 except TemplateDoesNotExist: 71 79 pass 72 80 raise TemplateDoesNotExist, name … … 76 84 Returns a compiled Template object for the given template name, 77 85 handling template inheritance recursively. 78 86 """ 79 source, origin = find_template_source(template_name) 80 template = get_template_from_string(source, origin, template_name) 81 return template 87 return find_template(template_name) 82 88 83 89 def get_template_from_string(source, origin=None, name=None): 84 90 """