From 3e2ae1b209ee8efc4283bb392c1fa5d6639d8c2a Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 21 Dec 2022 22:14:41 +0000 Subject: [PATCH] Totally unload debug toolbar outside of debug --- takahe/settings.py | 5 +++-- takahe/urls.py | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/takahe/settings.py b/takahe/settings.py index 5225fe9..d370254 100644 --- a/takahe/settings.py +++ b/takahe/settings.py @@ -176,7 +176,6 @@ INSTALLED_APPS = [ "django.contrib.messages", "django.contrib.staticfiles", "corsheaders", - "debug_toolbar", "django_htmx", "core", "activities", @@ -195,7 +194,6 @@ MIDDLEWARE = [ "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", - "debug_toolbar.middleware.DebugToolbarMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "django_htmx.middleware.HtmxMiddleware", @@ -311,8 +309,11 @@ MEDIA_URL = SETUP.MEDIA_URL MEDIA_ROOT = SETUP.MEDIA_ROOT MAIN_DOMAIN = SETUP.MAIN_DOMAIN +# Debug toolbar should only be loaded at all when debug is on if DEBUG: + INSTALLED_APPS.append("debug_toolbar") DEBUG_TOOLBAR_CONFIG = {"SHOW_TOOLBAR_CALLBACK": "core.middleware.show_toolbar"} + MIDDLEWARE.insert(8, "debug_toolbar.middleware.DebugToolbarMiddleware") if SETUP.USE_PROXY_HEADERS: SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") diff --git a/takahe/urls.py b/takahe/urls.py index 47e7dfd..124a9ee 100644 --- a/takahe/urls.py +++ b/takahe/urls.py @@ -248,8 +248,6 @@ urlpatterns = [ path(".stator/", stator.RequestRunner.as_view()), # Django admin path("djadmin/", djadmin.site.urls), - # Debug toolbar - path("__debug__/", include("debug_toolbar.urls")), # Media files re_path( r"^media/(?P.*)$", @@ -257,3 +255,7 @@ urlpatterns = [ kwargs={"document_root": djsettings.MEDIA_ROOT}, ), ] + +# Debug toolbar +if djsettings.DEBUG: + urlpatterns.append(path("__debug__/", include("debug_toolbar.urls")))