Repository: jazzband/django-debug-toolbar

Issue:
django.urls.exceptions.NoReverseMatch: 'djdt' is not a registered namespace
Hi there,

I'm trying to configure django-debug-toolbar. As of now i did the following : 

**settings.py**

`DEBUG=True`
`if DEBUG:`
    `INSTALLED_APPS += [
        "debug_toolbar",
    ]`

    MIDDLEWARE += [
        "debug_toolbar.middleware.DebugToolbarMiddleware",
    ]

    INTERNAL_IPS = [
        "127.0.0.1",
    ]

    DEBUG_TOOLBAR_PANELS = [
        "debug_toolbar.panels.versions.VersionsPanel",
        "debug_toolbar.panels.timer.TimerPanel",
        "debug_toolbar.panels.settings.SettingsPanel",
        "debug_toolbar.panels.headers.HeadersPanel",
        "debug_toolbar.panels.request.RequestPanel",
        "debug_toolbar.panels.sql.SQLPanel",
        "debug_toolbar.panels.staticfiles.StaticFilesPanel",
        "debug_toolbar.panels.templates.TemplatesPanel",
        "debug_toolbar.panels.cache.CachePanel",
        "debug_toolbar.panels.signals.SignalsPanel",
        "debug_toolbar.panels.logging.LoggingPanel",
        "debug_toolbar.panels.redirects.RedirectsPanel",
        "debug_toolbar.panels.profiling.ProfilingPanel",
    ]

    DEBUG_TOOLBAR_CONFIG = {
        "SHOW_TOOLBAR_CALLBACK": lambda request: DEBUG,
        "RESULTS_CACHE_SIZE": 3,
        "SHOW_COLLAPSED": True,
        "SQL_WARNING_THRESHOLD": 100,
    }

**urls.py**

`if settings.DEBUG:`

    import debug_toolbar

    urlpatterns = [path("__debug__/", include(debug_toolbar.urls)),] + urlpatterns

The toolbar is working correctly, but when i run `pytest tests/` or `docker-compose run --rm app pytest tests/` i get this error : 

**_django.urls.exceptions.NoReverseMatch: 'djdt' is not a registered namespace_**  for some tests suite.

So, what did i missed ??
Thank's in advance 


Discussion:
You should only include the debug toolbar's urls when `settings.DEBUG == True`. Then your tests should run with `DEBUG` set to `False`.
Thank you @tim-schilling for your response
I already tested this option and it works : setting `DEBUG=False` means tests pass but debug toolbar does not show in the browser.
My goal is to include debug toolbar and run tests with `DEBUG=True`
Is this possible ?
You could configure the debug toolbar with an environment variable, then run `runserver` with it set, such as `TOOLBAR="True" python manage.py runserver`

Or you can create a separate local settings file and use that in the call to runserver via `python manage.py runserver --settings=config.settings.local` where `config.settings.local` is the python path to your local settings file.

If you have it available, there's a chapter on Settings and Requirements files in Two Scoops of Django that goes into detail about this.

Resolving patch:
diff --git a/example/urls.py b/example/urls.py
--- a/example/urls.py
+++ b/example/urls.py
@@ -1,17 +1,14 @@
-from django.conf import settings
 from django.contrib import admin
 from django.urls import include, path
 from django.views.generic import TemplateView
 
+import debug_toolbar
+
 urlpatterns = [
     path("", TemplateView.as_view(template_name="index.html")),
     path("jquery/", TemplateView.as_view(template_name="jquery/index.html")),
     path("mootools/", TemplateView.as_view(template_name="mootools/index.html")),
     path("prototype/", TemplateView.as_view(template_name="prototype/index.html")),
     path("admin/", admin.site.urls),
+    path("__debug__/", include(debug_toolbar.urls)),
 ]
-
-if settings.DEBUG:
-    import debug_toolbar
-
-    urlpatterns += [path("__debug__/", include(debug_toolbar.urls))]


Test patch: