Repository: jazzband/django-debug-toolbar

Issue:
Include instructions on APP_DIRS in Prerequisites docs
So I was having `TemplateDoesNotExist` errors when trying to set up everything.

It took me some time to realize that for this package to work, you need to have `APP_DIRS: True` for debug_toolbar to include its templates in the projects.

Perhaps it's a good idea to include this in the documentation?


Discussion:
Yeah as a temporary solution that'd be good to put in the troubleshooting space. However, ideally the toolbar would work without it and if that's not possible, it'd fail gracefully and log a warning.
The `django.contrib.sitemaps` app also requires `"APP_DIRS": True`; we could have a look there how `"APP_DIRS": False` is handled. I couldn't find a check or anything (I didn't look long) so maybe it's enough to document the expectation that templates can be loaded from app dirs. 

(I haven't used `"APP_DIRS": False` or anything equivalent ever since beginning to use Django before 1.0, maybe this is exotic enough that we could simply ignore it. At least if it proves too much work to add a system check or something.)

Resolving patch:
diff --git a/debug_toolbar/apps.py b/debug_toolbar/apps.py
--- 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(


Test patch:
diff --git a/tests/test_checks.py b/tests/test_checks.py
--- 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",
+                )
+            ],
+        )