diff --git a/django/template/engine.py b/django/template/engine.py index ef5bcf628b..378fb4b20c 100644 --- a/django/template/engine.py +++ b/django/template/engine.py @@ -105,12 +105,11 @@ class Engine(object): "Invalid value in template loaders configuration: %r" % loader) def find_template(self, name, dirs=None): - # Inner import to avoid circular dependency - from .loader import make_origin for loader in self.template_loaders: try: source, display_name = loader(name, dirs) - return (source, make_origin(display_name, loader, name, dirs)) + origin = self.make_origin(display_name, loader, name, dirs) + return source, origin except TemplateDoesNotExist: pass raise TemplateDoesNotExist(name) @@ -214,3 +213,11 @@ class Engine(object): tokens = lexer.tokenize() parser = parser_class(tokens) return parser.parse() + + def make_origin(self, display_name, loader, name, dirs): + if settings.TEMPLATE_DEBUG and display_name: + # Inner import to avoid circular dependency + from .loader import LoaderOrigin + return LoaderOrigin(display_name, loader, name, dirs) + else: + return None diff --git a/django/template/loader.py b/django/template/loader.py index eb89ab5900..7d3d9f5097 100644 --- a/django/template/loader.py +++ b/django/template/loader.py @@ -1,6 +1,5 @@ import warnings -from django.conf import settings from django.utils.deprecation import RemovedInDjango20Warning from .base import Origin @@ -16,13 +15,6 @@ class LoaderOrigin(Origin): return self.loader(self.loadname, self.dirs)[0] -def make_origin(display_name, loader, name, dirs): - if settings.TEMPLATE_DEBUG and display_name: - return LoaderOrigin(display_name, loader, name, dirs) - else: - return None - - def find_template(*args, **kwargs): return Engine.get_default().find_template(*args, **kwargs) diff --git a/django/template/loaders/base.py b/django/template/loaders/base.py index 1a7df03f5e..bbcdd3aec2 100644 --- a/django/template/loaders/base.py +++ b/django/template/loaders/base.py @@ -1,5 +1,5 @@ from django.template.base import TemplateDoesNotExist -from django.template.loader import get_template_from_string, make_origin +from django.template.loader import get_template_from_string class Loader(object): @@ -16,7 +16,7 @@ class Loader(object): def load_template(self, template_name, template_dirs=None): source, display_name = self.load_template_source( template_name, template_dirs) - origin = make_origin( + origin = self.engine.make_origin( display_name, self.load_template_source, template_name, template_dirs) diff --git a/django/template/loaders/cached.py b/django/template/loaders/cached.py index b8cf48d237..fd058e1eaa 100644 --- a/django/template/loaders/cached.py +++ b/django/template/loaders/cached.py @@ -5,7 +5,7 @@ to load templates from them in order, caching the result. import hashlib from django.template.base import TemplateDoesNotExist -from django.template.loader import get_template_from_string, make_origin +from django.template.loader import get_template_from_string from django.utils.encoding import force_bytes from .base import Loader as BaseLoader @@ -42,7 +42,8 @@ class Loader(BaseLoader): except TemplateDoesNotExist: pass else: - result = (template, make_origin(display_name, loader, name, dirs)) + origin = self.engine.make_origin(display_name, loader, name, dirs) + result = template, origin break self.find_template_cache[key] = result if result: