Removed support for function-based template loaders.
They were deprecated in Django 1.2 but not all the supporting code was removed in Django 1.4. Since the remaining code was unlikely to be functional (pun intended) e.g. it would crash unless the loader function had an is_usable attribute, this commit completes the removal immediately instead of starting another deprecation path.
This commit is contained in:
parent
e87bee6f50
commit
fab26cf5e0
|
@ -4,7 +4,6 @@ from django.conf import settings
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.utils import lru_cache
|
from django.utils import lru_cache
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.deprecation import RemovedInDjango20Warning
|
|
||||||
from django.utils.module_loading import import_string
|
from django.utils.module_loading import import_string
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,34 +27,20 @@ def find_template_loader(loader):
|
||||||
loader, args = loader[0], loader[1:]
|
loader, args = loader[0], loader[1:]
|
||||||
else:
|
else:
|
||||||
args = []
|
args = []
|
||||||
|
|
||||||
if isinstance(loader, six.string_types):
|
if isinstance(loader, six.string_types):
|
||||||
TemplateLoader = import_string(loader)
|
loader_class = import_string(loader)
|
||||||
|
loader_instance = loader_class(*args)
|
||||||
|
|
||||||
if hasattr(TemplateLoader, 'load_template_source'):
|
if not loader_instance.is_usable:
|
||||||
func = TemplateLoader(*args)
|
|
||||||
else:
|
|
||||||
warnings.warn(
|
|
||||||
"Function-based template loaders are deprecated. "
|
|
||||||
"Please use class-based template loaders instead. "
|
|
||||||
"Inherit django.template.loaders.base.Loader "
|
|
||||||
"and provide a load_template_source() method.",
|
|
||||||
RemovedInDjango20Warning, stacklevel=2)
|
|
||||||
|
|
||||||
# Try loading module the old way - string is full path to callable
|
|
||||||
if args:
|
|
||||||
raise ImproperlyConfigured(
|
|
||||||
"Error importing template source loader %s - can't pass "
|
|
||||||
"arguments to function-based loader." % loader)
|
|
||||||
func = TemplateLoader
|
|
||||||
|
|
||||||
if not func.is_usable:
|
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"Your TEMPLATE_LOADERS setting includes %r, but your Python "
|
"Your TEMPLATE_LOADERS setting includes %r, but your Python "
|
||||||
"installation doesn't support that type of template loading. "
|
"installation doesn't support that type of template loading. "
|
||||||
"Consider removing that line from TEMPLATE_LOADERS." % loader)
|
"Consider removing that line from TEMPLATE_LOADERS." % loader)
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return func
|
return loader_instance
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ImproperlyConfigured(
|
raise ImproperlyConfigured(
|
||||||
"Invalid value in TEMPLATE_LOADERS: %r" % loader)
|
"Invalid value in TEMPLATE_LOADERS: %r" % loader)
|
||||||
|
|
|
@ -85,8 +85,6 @@ details on these changes.
|
||||||
* The backwards compatibility alias ``django.template.loader.BaseLoader`` will
|
* The backwards compatibility alias ``django.template.loader.BaseLoader`` will
|
||||||
be removed.
|
be removed.
|
||||||
|
|
||||||
* Support for function-based template loaders will be removed.
|
|
||||||
|
|
||||||
.. _deprecation-removed-in-1.9:
|
.. _deprecation-removed-in-1.9:
|
||||||
|
|
||||||
1.9
|
1.9
|
||||||
|
|
|
@ -1040,13 +1040,6 @@ class decorators. As a consequence, when overriding ``setUpClass()`` or
|
||||||
``django.template.loaders.base.Loader``. If you've written a custom template
|
``django.template.loaders.base.Loader``. If you've written a custom template
|
||||||
loader that inherits ``BaseLoader``, you must inherit ``Loader`` instead.
|
loader that inherits ``BaseLoader``, you must inherit ``Loader`` instead.
|
||||||
|
|
||||||
Function-based template loaders
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
In addition to the documented class-based API for custom template loaders,
|
|
||||||
Django still supported to some extent an earlier function-based API. This
|
|
||||||
private API wasn't maintained or tested. Now it's formally deprecated.
|
|
||||||
|
|
||||||
``django.test.utils.TestTemplateLoader``
|
``django.test.utils.TestTemplateLoader``
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue