141 | | # For backward compatibility |
142 | | import warnings |
143 | | warnings.warn( |
144 | | "`django.template.loader.find_template_source` is deprecated; use `django.template.loader.find_template` instead.", |
145 | | DeprecationWarning |
146 | | ) |
147 | | template, origin = find_template(name, dirs) |
148 | | if hasattr(template, 'render'): |
149 | | raise Exception("Found a compiled template that is incompatible with the deprecated `django.template.loader.find_template_source` function.") |
150 | | return template, origin |
| 141 | # Calculate template_source_loaders the first time the function is executed |
| 142 | # because putting this logic in the module-level namespace may cause |
| 143 | # circular import errors. See Django ticket #1292. |
| 144 | global template_source_loaders |
| 145 | if template_source_loaders is None: |
| 146 | loaders = [] |
| 147 | for loader_name in settings.TEMPLATE_LOADERS: |
| 148 | loader = find_template_loader(loader_name) |
| 149 | if loader is not None: |
| 150 | loaders.append(loader) |
| 151 | template_source_loaders = tuple(loaders) |
| 152 | def load_template_source(loaders): |
| 153 | for loader in loaders: |
| 154 | if hasattr(loader, 'loaders'): |
| 155 | try: |
| 156 | return load_template_source(loader.loaders) |
| 157 | except TemplateDoesNotExist: |
| 158 | pass |
| 159 | else: |
| 160 | try: |
| 161 | source, display_name = loader.load_template_source(name, dirs) |
| 162 | return (source, make_origin(display_name, loader, name, dirs)) |
| 163 | except TemplateDoesNotExist: |
| 164 | pass |
| 165 | raise TemplateDoesNotExist(name) |
| 166 | return load_template_source(template_source_loaders) |