Commits

Anonymous committed f9446f8

Refs #13573 -- Modified the key technique added in r13295 to be more robust against potential key collisions while keeping key names human-readable. Thanks to Alex for being finicky.

  • Participants
  • Parent commits b21b253

Comments (0)

Files changed (1)

django/template/loaders/cached.py

 to load templates from them in order, caching the result.
 """
 
+from django.core.exceptions import ImproperlyConfigured
 from django.template import TemplateDoesNotExist
 from django.template.loader import BaseLoader, get_template_from_string, find_template_loader, make_origin
+from django.utils.hashcompat import sha_constructor
 from django.utils.importlib import import_module
-from django.core.exceptions import ImproperlyConfigured
 
 class Loader(BaseLoader):
     is_usable = True
         raise TemplateDoesNotExist(name)
 
     def load_template(self, template_name, template_dirs=None):
-        # Use hash(..) to avoid saving potentially large template_dirs values
-        key = hash((template_name, template_dirs))
+        key = template_name
+        if template_dirs:
+            # If template directories were specified, use a hash to differentiate
+            key = '-'.join([template_name, sha_constructor('|'.join(template_dirs)).hexdigest()])
 
         if key not in self.template_cache:
             template, origin = self.find_template(template_name, template_dirs)