diff --git a/django/core/template/loader.py b/django/core/template/loader.py index 10989424dbd53..6d747d560d4ba 100644 --- a/django/core/template/loader.py +++ b/django/core/template/loader.py @@ -59,7 +59,7 @@ def make_origin(display_name, loader, name, dirs): def find_template_source(name, dirs=None): for loader in template_source_loaders: try: - source, display_name = loader(name, dirs) + source, display_name = loader(name, dirs) return (source, make_origin(display_name, loader, name, dirs)) except TemplateDoesNotExist: pass diff --git a/django/core/template/loaders/app_directories.py b/django/core/template/loaders/app_directories.py index d7c02c68eafaf..390e47852e088 100644 --- a/django/core/template/loaders/app_directories.py +++ b/django/core/template/loaders/app_directories.py @@ -27,9 +27,12 @@ # It won't change, so convert it to a tuple to save memory. app_template_dirs = tuple(app_template_dirs) -def load_template_source(template_name, template_dirs=None): +def get_template_sources(template_name, template_dirs=None): for template_dir in app_template_dirs: - filepath = os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION + yield os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION + +def load_template_source(template_name, template_dirs=None): + for filepath in get_template_sources(template_name, template_dirs): try: return (open(filepath).read(), filepath) except IOError: diff --git a/django/core/template/loaders/filesystem.py b/django/core/template/loaders/filesystem.py index 9a934817057ad..23ce6cd9e4bb3 100644 --- a/django/core/template/loaders/filesystem.py +++ b/django/core/template/loaders/filesystem.py @@ -4,12 +4,15 @@ from django.core.template import TemplateDoesNotExist import os -def load_template_source(template_name, template_dirs=None): +def get_template_sources(template_name, template_dirs=None): if not template_dirs: template_dirs = TEMPLATE_DIRS - tried = [] for template_dir in template_dirs: - filepath = os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION + yield os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION + +def load_template_source(template_name, template_dirs=None): + tried = [] + for filepath in get_template_sources(template_name, template_dirs): try: return (open(filepath).read(), filepath) except IOError: