diff --git a/AUTHORS b/AUTHORS index 5ad1569e27..4484c9ba46 100644 --- a/AUTHORS +++ b/AUTHORS @@ -420,6 +420,7 @@ answer newbie questions, and generally made Django that much better: mark@junklight.com Orestis Markou Andrés Torres Marroquín + Pablo Martín Takashi Matsuo Zlatko Mašek Yasushi Masuda diff --git a/django/template/loaders/cached.py b/django/template/loaders/cached.py index 646168cd1e..1ed7c7f96a 100644 --- a/django/template/loaders/cached.py +++ b/django/template/loaders/cached.py @@ -53,6 +53,7 @@ class Loader(BaseLoader): pass else: result = (template, make_origin(display_name, loader, name, dirs)) + break self.find_template_cache[key] = result if result: return result diff --git a/tests/template_tests/templates/priority/foo.html b/tests/template_tests/templates/priority/foo.html new file mode 100644 index 0000000000..df6a819411 --- /dev/null +++ b/tests/template_tests/templates/priority/foo.html @@ -0,0 +1 @@ +no priority diff --git a/tests/template_tests/test_loaders.py b/tests/template_tests/test_loaders.py index 57da0af56e..6e74477e83 100644 --- a/tests/template_tests/test_loaders.py +++ b/tests/template_tests/test_loaders.py @@ -189,3 +189,33 @@ class TemplateDirsOverrideTest(unittest.TestCase): for dirs in self.dirs_iter: template = loader.select_template(['test_dirs.html'], dirs=dirs) self.assertEqual(template.render(Context({})), 'spam eggs\n') + + +@override_settings( + TEMPLATE_LOADERS=( + ('django.template.loaders.cached.Loader', ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', + )), + ) +) +class PriorityCacheLoader(TestCase): + def test_basic(self): + """ + Check that the order of template loader works. Refs #21460. + """ + t1, name = loader.find_template('priority/foo.html') + self.assertEqual(t1.render(Context({})), 'priority\n') + + +@override_settings( + TEMPLATE_LOADERS=('django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader',), +) +class PriorityLoader(TestCase): + def test_basic(self): + """ + Check that the order of template loader works. Refs #21460. + """ + t1, name = loader.find_template('priority/foo.html') + self.assertEqual(t1.render(Context({})), 'priority\n') diff --git a/tests/templates/priority/foo.html b/tests/templates/priority/foo.html new file mode 100644 index 0000000000..4d8014f9ad --- /dev/null +++ b/tests/templates/priority/foo.html @@ -0,0 +1 @@ +priority