diff --git a/django/template/engine.py b/django/template/engine.py index 9e6f1e97da..f2215c0e4e 100644 --- a/django/template/engine.py +++ b/django/template/engine.py @@ -38,8 +38,7 @@ class Engine: loaders = ["django.template.loaders.filesystem.Loader"] if app_dirs: loaders += ["django.template.loaders.app_directories.Loader"] - if not debug: - loaders = [("django.template.loaders.cached.Loader", loaders)] + loaders = [("django.template.loaders.cached.Loader", loaders)] else: if app_dirs: raise ImproperlyConfigured( diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt index 1082823e71..2e0adb0046 100644 --- a/docs/ref/templates/api.txt +++ b/docs/ref/templates/api.txt @@ -99,9 +99,14 @@ overridden by what's passed by * ``'django.template.loaders.app_directories.Loader'`` if and only if ``app_dirs`` is ``True``. - If ``debug`` is ``False``, these loaders are wrapped in + These loaders are then wrapped in :class:`django.template.loaders.cached.Loader`. + .. versionchanged:: 4.1 + + In older versions, the cached template loader was only enabled by + default when ``DEBUG`` was ``False``. + See :ref:`template-loaders` for details. * ``string_if_invalid`` is the output, as a string, that the template @@ -905,10 +910,9 @@ loaders that come with Django: .. class:: cached.Loader - By default (when :setting:`DEBUG` is ``True``), the template system reads - and compiles your templates every time they're rendered. While the Django - template system is quite fast, the overhead from reading and compiling - templates can add up. + While the Django template system is quite fast, if it needs to read and + compile your templates every time they're rendered, the overhead from that + can add up. You configure the cached template loader with a list of other loaders that it should wrap. The wrapped loaders are used to locate unknown templates @@ -917,11 +921,9 @@ loaders that come with Django: subsequent requests to load the same template. This loader is automatically enabled if :setting:`OPTIONS['loaders'] - ` isn't specified and :setting:`OPTIONS['debug'] - ` is ``False`` (the latter option defaults to the value - of :setting:`DEBUG`). + ` isn't specified. - You can also enable template caching with some custom template loaders + You can manually specify template caching with some custom template loaders using settings like this:: TEMPLATES = [{ @@ -947,6 +949,12 @@ loaders that come with Django: information, see :ref:`template tag thread safety considerations `. + .. versionchanged:: 4.1 + + The cached template loader was enabled whenever ``OPTIONS['loaders']`` + is not specified. Previously it was only enabled when ``DEBUG`` was + ``False``. + ``django.template.loaders.locmem.Loader`` .. class:: locmem.Loader diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt index f248e1f21e..e84a47dd2d 100644 --- a/docs/releases/4.1.txt +++ b/docs/releases/4.1.txt @@ -339,12 +339,19 @@ Signals :data:`~django.db.models.signals.post_delete` signals now dispatch the ``origin`` of the deletion. +.. _templates-4.1: + Templates ~~~~~~~~~ * :tfilter:`json_script` template filter now allows wrapping in a ``