From 3742757583b31964db46be692f0ca3d85cef475c Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Sat, 28 Aug 2021 11:49:45 -0500 Subject: [PATCH 1/2] Add check and docs for TEMPLATES APP_DIRS=False. The toolbar requires at least one DjangoTemplates TEMPLATES configuration needs to have APP_DIRS set to True. --- debug_toolbar/apps.py | 14 ++++++++++++++ docs/changes.rst | 2 ++ docs/checks.rst | 2 ++ docs/installation.rst | 5 +++++ tests/test_checks.py | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+) diff --git a/debug_toolbar/apps.py b/debug_toolbar/apps.py index eec750a3b..69464c64d 100644 --- a/debug_toolbar/apps.py +++ b/debug_toolbar/apps.py @@ -23,6 +23,20 @@ def check_middleware(app_configs, **kwargs): gzip_index = None debug_toolbar_indexes = [] + if all(not config.get("APP_DIRS", False) for config in settings.TEMPLATES): + errors.append( + Warning( + "At least one DjangoTemplates TEMPLATES configuration needs " + "to have APP_DIRS set to True.", + hint=( + "Use APP_DIRS=True for at least one " + "django.template.backends.django.DjangoTemplates " + "backend configuration." + ), + id="debug_toolbar.W006", + ) + ) + # If old style MIDDLEWARE_CLASSES is being used, report an error. if settings.is_overridden("MIDDLEWARE_CLASSES"): errors.append( diff --git a/docs/changes.rst b/docs/changes.rst index f2b4f30a7..1a1a654e4 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -9,6 +9,8 @@ Next version ``django.core.caches`` as a whole. The ``middleware.cache`` is still being patched as a whole in order to attempt to catch any cache usages before ``enable_instrumentation`` is called. +* Add check ``W006`` to warn that the toolbar is incompatible with + ``TEMPLATES`` settings configurations with ``APP_DIRS`` set to ``False``. 3.2.2 (2021-08-14) diff --git a/docs/checks.rst b/docs/checks.rst index 8575ed565..4d4882db6 100644 --- a/docs/checks.rst +++ b/docs/checks.rst @@ -14,3 +14,5 @@ Debug Toolbar setup and configuration: * **debug_toolbar.W004**: ``debug_toolbar`` is incompatible with ``MIDDLEWARE_CLASSES`` setting. * **debug_toolbar.W005**: Setting ``DEBUG_TOOLBAR_PANELS`` is empty. +* **debug_toolbar.W006**: At least one ``DjangoTemplates`` ``TEMPLATES`` + configuration needs to have ``APP_DIRS`` set to ``True``. diff --git a/docs/installation.rst b/docs/installation.rst index 4eff7fc89..f800db86b 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -37,6 +37,11 @@ Make sure that ``'django.contrib.staticfiles'`` is `set up properly STATIC_URL = '/static/' +Make sure your ``TEMPLATES`` setting contains a ``DjangoTemplates`` backend +whose ``APP_DIRS`` options is set to ``True``. It’s in there by default, so +you’ll only need to change this if you’ve changed that setting. + + If you're upgrading from a previous version, you should review the :doc:`change log ` and look for specific upgrade instructions. diff --git a/tests/test_checks.py b/tests/test_checks.py index a1c59614a..15464f9a2 100644 --- a/tests/test_checks.py +++ b/tests/test_checks.py @@ -122,3 +122,37 @@ def test_panels_is_empty(self): ) ], ) + + @override_settings( + TEMPLATES=[ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "APP_DIRS": False, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ] + }, + }, + ] + ) + def test_templates_is_using_app_dirs_false(self): + errors = run_checks() + self.assertEqual( + errors, + [ + Warning( + "At least one DjangoTemplates TEMPLATES configuration " + "needs to have APP_DIRS set to True.", + hint=( + "Use APP_DIRS=True for at least one " + "django.template.backends.django.DjangoTemplates " + "backend configuration." + ), + id="debug_toolbar.W006", + ) + ], + ) From be21a990cc67596e5ba80a5194e61da30d6e0530 Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Sat, 28 Aug 2021 11:58:55 -0500 Subject: [PATCH 2/2] Dang pretty apostrophe's being copied from the web. --- docs/installation.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index f800db86b..27a6b6b85 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -38,8 +38,8 @@ Make sure that ``'django.contrib.staticfiles'`` is `set up properly STATIC_URL = '/static/' Make sure your ``TEMPLATES`` setting contains a ``DjangoTemplates`` backend -whose ``APP_DIRS`` options is set to ``True``. It’s in there by default, so -you’ll only need to change this if you’ve changed that setting. +whose ``APP_DIRS`` options is set to ``True``. It's in there by default, so +you'll only need to change this if you've changed that setting. If you're upgrading from a previous version, you should review the