Django Debug Toolbar: don't crash when not installed

It happens with some regularity that people notice the "DEBUG" setting
and try to run with DEBUG=True. Although this is not documented nor recommended
you can't really blame 'm, and it would probably help them debug their issues.

Pre-this-commit that was not possible, because the debug toolbar is usually not
installed (and on e.g. on Docker this is very annoying to do).
This commit is contained in:
Klaas van Schelven
2025-03-19 08:30:40 +01:00
parent eb780c0008
commit 38d49f5000

View File

@@ -63,9 +63,16 @@ if settings.DEBUG:
path('debug-users-email/<str:template_name>/', debug_users_email),
path('debug-teams-email/<str:template_name>/', debug_teams_email),
path('trigger-error/', trigger_error),
path("__debug__/", include("debug_toolbar.urls")),
]
try:
import debug_toolbar # noqa
urlpatterns = [
path('__debug__/', include('debug_toolbar.urls')),
] + urlpatterns
except ImportError:
pass
handler400 = "bugsink.views.bad_request"
handler403 = "bugsink.views.permission_denied"