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

Fixed 19949 -- Cached template loader now caches TemplateDoesNotExist

Thanks @timgraham and @jdunck for the code reviews and Kronuz for bug
report and initial patch.
This commit is contained in:
SusanTan
2013-08-21 11:23:53 -07:00
committed by Tim Graham
parent 35230adf63
commit f33db5a09a
2 changed files with 19 additions and 6 deletions

View File

@@ -57,9 +57,11 @@ class Loader(BaseLoader):
def load_template(self, template_name, template_dirs=None):
key = self.cache_key(template_name, template_dirs)
try:
template = self.template_cache[key]
except KeyError:
template_tuple = self.template_cache.get(key)
# cached a previous failure:
if template_tuple is TemplateDoesNotExist:
raise TemplateDoesNotExist
elif template_tuple is None:
template, origin = self.find_template(template_name, template_dirs)
if not hasattr(template, 'render'):
try:
@@ -69,9 +71,9 @@ class Loader(BaseLoader):
# 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[key] = template
return template, None
self.template_cache[key] = (template, origin)
self.template_cache[key] = (template, None)
return self.template_cache[key]
def reset(self):
"Empty the template cache."