1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

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
This commit is contained in:
Karen Tracey
2010-03-16 14:34:57 +00:00
parent e89a5e06cf
commit 80e744945c
6 changed files with 117 additions and 36 deletions

View File

@@ -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)
template = get_template_from_string(source, origin, template_name)
return template, None
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):
"""

View File

@@ -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)
return get_template(parent)
def render(self, context):
compiled_parent = self.get_parent(context)

View File

@@ -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'):
template = get_template_from_string(template, origin, template_name)
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