mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #17061 -- Factored out importing object from a dotted path
Thanks Carl Meyer for the report.
This commit is contained in:
		| @@ -1,6 +1,5 @@ | ||||
| from copy import copy | ||||
| from django.core.exceptions import ImproperlyConfigured | ||||
| from django.utils.importlib import import_module | ||||
| from django.utils.module_loading import import_by_path | ||||
|  | ||||
| # Cache of actual callables. | ||||
| _standard_context_processors = None | ||||
| @@ -146,16 +145,7 @@ def get_standard_processors(): | ||||
|         collect.extend(_builtin_context_processors) | ||||
|         collect.extend(settings.TEMPLATE_CONTEXT_PROCESSORS) | ||||
|         for path in collect: | ||||
|             i = path.rfind('.') | ||||
|             module, attr = path[:i], path[i+1:] | ||||
|             try: | ||||
|                 mod = import_module(module) | ||||
|             except ImportError as e: | ||||
|                 raise ImproperlyConfigured('Error importing request processor module %s: "%s"' % (module, e)) | ||||
|             try: | ||||
|                 func = getattr(mod, attr) | ||||
|             except AttributeError: | ||||
|                 raise ImproperlyConfigured('Module "%s" does not define a "%s" callable request processor' % (module, attr)) | ||||
|             func = import_by_path(path) | ||||
|             processors.append(func) | ||||
|         _standard_context_processors = tuple(processors) | ||||
|     return _standard_context_processors | ||||
|   | ||||
| @@ -27,8 +27,8 @@ | ||||
|  | ||||
| from django.core.exceptions import ImproperlyConfigured | ||||
| from django.template.base import Origin, Template, Context, TemplateDoesNotExist, add_to_builtins | ||||
| from django.utils.importlib import import_module | ||||
| from django.conf import settings | ||||
| from django.utils.module_loading import import_by_path | ||||
| from django.utils import six | ||||
|  | ||||
| template_source_loaders = None | ||||
| @@ -91,15 +91,7 @@ def find_template_loader(loader): | ||||
|     else: | ||||
|         args = [] | ||||
|     if isinstance(loader, six.string_types): | ||||
|         module, attr = loader.rsplit('.', 1) | ||||
|         try: | ||||
|             mod = import_module(module) | ||||
|         except ImportError as e: | ||||
|             raise ImproperlyConfigured('Error importing template source loader %s: "%s"' % (loader, e)) | ||||
|         try: | ||||
|             TemplateLoader = getattr(mod, attr) | ||||
|         except AttributeError as e: | ||||
|             raise ImproperlyConfigured('Error importing template source loader %s: "%s"' % (loader, e)) | ||||
|         TemplateLoader = import_by_path(loader) | ||||
|  | ||||
|         if hasattr(TemplateLoader, 'load_template_source'): | ||||
|             func = TemplateLoader(*args) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user