8000 Refs #13573 -- Modified the key technique added in r13295 to be more … · ddriddle/django@84060a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 84060a1

Browse files
committed
Refs django#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.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13299 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 5acd9cd commit 84060a1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

django/template/loaders/cached.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
to load templates from them in order, caching the result.
44
"""
55

6+
from django.core.exceptions import ImproperlyConfigured
67
from django.template import TemplateDoesNotExist
78
from django.template.loader import BaseLoader, get_template_from_string, find_template_loader, make_origin
9+
from django.utils.hashcompat import sha_constructor
810
from django.utils.importlib import import_module
9-
from django.core.exceptions import ImproperlyConfigured
1011

1112
class Loader(BaseLoader):
1213
is_usable = True
@@ -34,8 +35,10 @@ def find_template(self, name, dirs=None):
3435
raise TemplateDoesNotExist(name)
3536

3637
def load_template(self, template_name, template_dirs=None):
37-
# Use hash(..) to avoid saving potentially large template_dirs values
38-
key = hash((template_name, template_dirs))
38+
key = template_name
39+
if template_dirs:
40+
# If template directories were specified, use a hash to differentiate
41+
key = '-'.join([template_name, sha_constructor('|'.join(template_dirs)).hexdigest()])
3942

4043
if key not in self.template_cache:
4144
template, origin = self.find_template(template_name, template_dirs)

0 commit comments

Comments
 (0)
0