Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added further fixes, tests for #19949/f33db5a09a.

Thanks Susan Tan. Refs #19949.
  • Loading branch information...
commit b785a80d1934ef05165f222779c3f47c32889825 1 parent 51a9a59
Ramiro Morales authored August 24, 2013
6  django/template/loaders/cached.py
@@ -37,6 +37,9 @@ def cache_key(self, template_name, template_dirs):
37 37
             return template_name
38 38
 
39 39
     def find_template(self, name, dirs=None):
  40
+        """
  41
+        Helper method. Lookup the template :param name: in all the configured loaders
  42
+        """
40 43
         key = self.cache_key(name, dirs)
41 44
         try:
42 45
             result = self.find_template_cache[key]
@@ -53,12 +56,13 @@ def find_template(self, name, dirs=None):
53 56
         if result:
54 57
             return result
55 58
         else:
  59
+            self.template_cache[key] = TemplateDoesNotExist
56 60
             raise TemplateDoesNotExist(name)
57 61
 
58 62
     def load_template(self, template_name, template_dirs=None):
59 63
         key = self.cache_key(template_name, template_dirs)
60 64
         template_tuple = self.template_cache.get(key)
61  
-        # cached a previous failure:
  65
+        # A cached previous failure:
62 66
         if template_tuple is TemplateDoesNotExist:
63 67
             raise TemplateDoesNotExist
64 68
         elif template_tuple is None:
10  tests/template_tests/test_loaders.py
@@ -129,13 +129,19 @@ def test_templatedir_caching(self):
129 129
         self.assertNotEqual(t1.render(Context({})), t2.render(Context({})))
130 130
 
131 131
     def test_missing_template_is_cached(self):
132  
-        "Check that the missing template is cached."
  132
+        "#19949 -- Check that the missing template is cached."
133 133
         template_loader = loader.find_template_loader(settings.TEMPLATE_LOADERS[0])
134 134
         # Empty cache, which may be filled from previous tests.
135 135
         template_loader.reset()
136  
-        # Check that 'missing.html' isn't already in cache before 'missing.html' is loaed
  136
+        # Check that 'missing.html' isn't already in cache before 'missing.html' is loaded
137 137
         self.assertRaises(KeyError, lambda: template_loader.template_cache["missing.html"])
  138
+        # Try to load it, it should fail
138 139
         self.assertRaises(TemplateDoesNotExist, template_loader.load_template, "missing.html")
  140
+        # Verify that the fact that the missing template, which hasn't been found, has actually
  141
+        # been cached:
  142
+        self.assertEqual(template_loader.template_cache.get("missing.html"),
  143
+                         TemplateDoesNotExist,
  144
+                         "Cached template loader doesn't cache file lookup misses. It should.")
139 145
 
140 146
 
141 147
 class RenderToStringTest(unittest.TestCase):

0 notes on commit b785a80

Please sign in to comment.
Something went wrong with that request. Please try again.