From 38d49f500094dcd958d4441d95d8feb5d7e993ad Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Wed, 19 Mar 2025 08:30:40 +0100 Subject: [PATCH] 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). --- bugsink/urls.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bugsink/urls.py b/bugsink/urls.py index 0d6c597..84243c1 100644 --- a/bugsink/urls.py +++ b/bugsink/urls.py @@ -63,9 +63,16 @@ if settings.DEBUG: path('debug-users-email//', debug_users_email), path('debug-teams-email//', 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"