Commit 80e74494 authored by Karen Tracey's avatar Karen Tracey
Browse files

Fixed #12787: Correctly identify the template that does not exist when a...

Fixed #12787: Correctly identify the template that does not exist when a template being extended includes another template that does not exist. Thanks to trigeek38 for the report.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@12792 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent e89a5e06
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -44,8 +44,15 @@ class BaseLoader(object):
    def load_template(self, template_name, template_dirs=None):
        source, display_name = self.load_template_source(template_name, template_dirs)
        origin = make_origin(display_name, self.load_template_source, template_name, template_dirs)
        try:
            template = get_template_from_string(source, origin, template_name)
            return template, None
        except TemplateDoesNotExist:
            # If compiling the template we found raises TemplateDoesNotExist, back off to 
            # returning the source and display name for the template we were asked to load.
            # This allows for correct identification (later) of the actual template that does 
            # not exist.
            return source, display_name

    def load_template_source(self, template_name, template_dirs=None):
        """
+1 −4
Original line number Diff line number Diff line
@@ -97,10 +97,7 @@ class ExtendsNode(Node):
            raise TemplateSyntaxError(error_msg)
        if hasattr(parent, 'render'):
            return parent # parent is a Template object
        try:
        return get_template(parent)
        except TemplateDoesNotExist:
            raise TemplateSyntaxError("Template %r cannot be extended, because it doesn't exist" % parent)

    def render(self, context):
        compiled_parent = self.get_parent(context)
+8 −1
Original line number Diff line number Diff line
@@ -37,7 +37,14 @@ class Loader(BaseLoader):
        if template_name not in self.template_cache:
            template, origin = self.find_template(template_name, template_dirs)
            if not hasattr(template, 'render'):
                try:
                    template = get_template_from_string(template, origin, template_name)
                except TemplateDoesNotExist:
                    # If compiling the template we found raises TemplateDoesNotExist, 
                    # back off to returning the source and display name for the template 
                    # we were asked to load. This allows for correct identification (later) 
                    # of the actual template that does not exist.
                    return template, origin
            self.template_cache[template_name] = template
        return self.template_cache[template_name], None

+1 −0
Original line number Diff line number Diff line
{% include "missing.html" %}
+1 −0
Original line number Diff line number Diff line
{% extends "broken_base.html" %}
Loading