Loading django/template/loaders/cached.py +2 −2 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ import warnings from django.template import Origin, Template, TemplateDoesNotExist from django.template.backends.django import copy_exception from django.utils.deprecation import RemovedInDjango20Warning from django.utils.encoding import force_bytes from django.utils.encoding import force_bytes, force_text from django.utils.inspect import func_supports_parameter from .base import Loader as BaseLoader Loading Loading @@ -100,7 +100,7 @@ class Loader(BaseLoader): if template_dirs: dirs_prefix = self.generate_hash(template_dirs) return '-'.join(filter(bool, [template_name, skip_prefix, dirs_prefix])) return '-'.join(filter(bool, [force_text(template_name), skip_prefix, dirs_prefix])) def generate_hash(self, values): return hashlib.sha1(force_bytes('|'.join(values))).hexdigest() Loading docs/releases/1.9.7.txt +3 −0 Original line number Diff line number Diff line Loading @@ -14,3 +14,6 @@ Bugfixes * Fixed translation of password validators' ``help_text`` in forms (:ticket:`26544`). * Fixed a regression causing the cached template loader to crash when using lazy template names (:ticket:`26603`). tests/template_tests/test_loaders.py +8 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ from django.template.engine import Engine from django.test import SimpleTestCase, ignore_warnings, override_settings from django.utils import six from django.utils.deprecation import RemovedInDjango20Warning from django.utils.functional import lazystr from .utils import TEMPLATE_DIR Loading Loading @@ -153,6 +154,13 @@ class CachedLoaderTests(SimpleTestCase): """ self.assertEqual(self.engine.template_loaders[0].cache_key('-template.html', []), '-template.html') def test_template_name_lazy_string(self): """ #26603 -- A template name specified as a lazy string should be forced to text before computing its cache key. """ self.assertEqual(self.engine.template_loaders[0].cache_key(lazystr('template.html'), []), 'template.html') @unittest.skipUnless(pkg_resources, 'setuptools is not installed') class EggLoaderTests(SimpleTestCase): Loading Loading
django/template/loaders/cached.py +2 −2 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ import warnings from django.template import Origin, Template, TemplateDoesNotExist from django.template.backends.django import copy_exception from django.utils.deprecation import RemovedInDjango20Warning from django.utils.encoding import force_bytes from django.utils.encoding import force_bytes, force_text from django.utils.inspect import func_supports_parameter from .base import Loader as BaseLoader Loading Loading @@ -100,7 +100,7 @@ class Loader(BaseLoader): if template_dirs: dirs_prefix = self.generate_hash(template_dirs) return '-'.join(filter(bool, [template_name, skip_prefix, dirs_prefix])) return '-'.join(filter(bool, [force_text(template_name), skip_prefix, dirs_prefix])) def generate_hash(self, values): return hashlib.sha1(force_bytes('|'.join(values))).hexdigest() Loading
docs/releases/1.9.7.txt +3 −0 Original line number Diff line number Diff line Loading @@ -14,3 +14,6 @@ Bugfixes * Fixed translation of password validators' ``help_text`` in forms (:ticket:`26544`). * Fixed a regression causing the cached template loader to crash when using lazy template names (:ticket:`26603`).
tests/template_tests/test_loaders.py +8 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ from django.template.engine import Engine from django.test import SimpleTestCase, ignore_warnings, override_settings from django.utils import six from django.utils.deprecation import RemovedInDjango20Warning from django.utils.functional import lazystr from .utils import TEMPLATE_DIR Loading Loading @@ -153,6 +154,13 @@ class CachedLoaderTests(SimpleTestCase): """ self.assertEqual(self.engine.template_loaders[0].cache_key('-template.html', []), '-template.html') def test_template_name_lazy_string(self): """ #26603 -- A template name specified as a lazy string should be forced to text before computing its cache key. """ self.assertEqual(self.engine.template_loaders[0].cache_key(lazystr('template.html'), []), 'template.html') @unittest.skipUnless(pkg_resources, 'setuptools is not installed') class EggLoaderTests(SimpleTestCase): Loading