Skip to content

Commit e20ac73

Browse files
Add check and docs for TEMPLATES APP_DIRS=False. (#1498)
* 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.
1 parent 6cc6265 commit e20ac73

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

debug_toolbar/apps.py

+14
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ def check_middleware(app_configs, **kwargs):
2323
gzip_index = None
2424
debug_toolbar_indexes = []
2525

26+
if all(not config.get("APP_DIRS", False) for config in settings.TEMPLATES):
27+
errors.append(
28+
Warning(
29+
"At least one DjangoTemplates TEMPLATES configuration needs "
30+
"to have APP_DIRS set to True.",
31+
hint=(
32+
"Use APP_DIRS=True for at least one "
33+
"django.template.backends.django.DjangoTemplates "
34+
"backend configuration."
35+
),
36+
id="debug_toolbar.W006",
37+
)
38+
)
39+
2640
# If old style MIDDLEWARE_CLASSES is being used, report an error.
2741
if settings.is_overridden("MIDDLEWARE_CLASSES"):
2842
errors.append(

docs/changes.rst

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Next version
99
``django.core.caches`` as a whole. The ``middleware.cache`` is still
1010
being patched as a whole in order to attempt to catch any cache
1111
usages before ``enable_instrumentation`` is called.
12+
* Add check ``W006`` to warn that the toolbar is incompatible with
13+
``TEMPLATES`` settings configurations with ``APP_DIRS`` set to ``False``.
1214

1315

1416
3.2.2 (2021-08-14)

docs/checks.rst

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ Debug Toolbar setup and configuration:
1414
* **debug_toolbar.W004**: ``debug_toolbar`` is incompatible with
1515
``MIDDLEWARE_CLASSES`` setting.
1616
* **debug_toolbar.W005**: Setting ``DEBUG_TOOLBAR_PANELS`` is empty.
17+
* **debug_toolbar.W006**: At least one ``DjangoTemplates`` ``TEMPLATES``
18+
configuration needs to have ``APP_DIRS`` set to ``True``.

docs/installation.rst

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ Make sure that ``'django.contrib.staticfiles'`` is `set up properly
3737

3838
STATIC_URL = '/static/'
3939

40+
Make sure your ``TEMPLATES`` setting contains a ``DjangoTemplates`` backend
41+
whose ``APP_DIRS`` options is set to ``True``. It's in there by default, so
42+
you'll only need to change this if you've changed that setting.
43+
44+
4045
If you're upgrading from a previous version, you should review the
4146
:doc:`change log <changes>` and look for specific upgrade instructions.
4247

tests/test_checks.py

+34
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,37 @@ def test_panels_is_empty(self):
122122
)
123123
],
124124
)
125+
126+
@override_settings(
127+
TEMPLATES=[
128+
{
129+
"BACKEND": "django.template.backends.django.DjangoTemplates",
130+
"APP_DIRS": False,
131+
"OPTIONS": {
132+
"context_processors": [
133+
"django.template.context_processors.debug",
134+
"django.template.context_processors.request",
135+
"django.contrib.auth.context_processors.auth",
136+
"django.contrib.messages.context_processors.messages",
137+
]
138+
},
139+
},
140+
]
141+
)
142+
def test_templates_is_using_app_dirs_false(self):
143+
errors = run_checks()
144+
self.assertEqual(
145+
errors,
146+
[
147+
Warning(
148+
"At least one DjangoTemplates TEMPLATES configuration "
149+
"needs to have APP_DIRS set to True.",
150+
hint=(
151+
"Use APP_DIRS=True for at least one "
152+
"django.template.backends.django.DjangoTemplates "
153+
"backend configuration."
154+
),
155+
id="debug_toolbar.W006",
156+
)
157+
],
158+
)

0 commit comments

Comments
 (0)