Ticket #6691: templateloader.diff

File templateloader.diff, 2.8 KB (added by redvasily, 17 years ago)

Diff implementing this ticket

  • django/template/loader_tags.py

     
    11from django.template import TemplateSyntaxError, TemplateDoesNotExist, Variable
    22from django.template import Library, Node, TextNode
    3 from django.template.loader import get_template, get_template_from_string, find_template_source
     3from django.template.loader import get_template, find_template
    44from django.conf import settings
    55from django.utils.safestring import mark_safe
    66
     
    6161        if hasattr(parent, 'render'):
    6262            return parent # parent is a Template object
    6363        try:
    64             source, origin = find_template_source(parent, self.template_dirs)
     64            template = find_template(parent, self.template_dirs)
    6565        except TemplateDoesNotExist:
    6666            raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent
    6767        else:
    68             return get_template_from_string(source, origin, parent)
     68            return template
    6969
    7070    def render(self, context):
    7171        compiled_parent = self.get_parent(context)
  • django/template/loader.py

     
    4040    else:
    4141        return None
    4242
    43 def find_template_source(name, dirs=None):
     43def find_template(name, dirs=None):
    4444    # Calculate template_source_loaders the first time the function is executed
    4545    # because putting this logic in the module-level namespace may cause
    4646    # circular import errors. See Django ticket #1292.
     
    6565                template_source_loaders.append(func)
    6666    for loader in template_source_loaders:
    6767        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
    7078        except TemplateDoesNotExist:
    7179            pass
    7280    raise TemplateDoesNotExist, name
     
    7684    Returns a compiled Template object for the given template name,
    7785    handling template inheritance recursively.
    7886    """
    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)
    8288
    8389def get_template_from_string(source, origin=None, name=None):
    8490    """
Back to Top