From d350b7bcd8c0bfe49ec31808460314c26e2180bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Mon, 9 Feb 2026 22:22:38 +0100 Subject: [PATCH] Add django-debug-toolbar --- config/settings.py | 16 +++++++++++++--- config/urls.py | 9 ++++++--- pyproject.toml | 1 + 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/config/settings.py b/config/settings.py index a415818..58b47a1 100644 --- a/config/settings.py +++ b/config/settings.py @@ -39,7 +39,7 @@ def env_int(key: str, default: int) -> int: DEBUG: bool = env_bool(key="DEBUG", default=True) -RUNNING_TESTS: bool = "PYTEST_VERSION" in os.environ or any("pytest" in arg for arg in sys.argv) +TESTING: bool = "test" in sys.argv or "PYTEST_VERSION" in os.environ def get_data_dir() -> Path: @@ -142,12 +142,10 @@ INSTALLED_APPS: list[str] = [ "django.contrib.contenttypes", "django.contrib.staticfiles", "twitch.apps.TwitchConfig", - *(["silk"] if not RUNNING_TESTS else []), ] MIDDLEWARE: list[str] = [ "django.middleware.security.SecurityMiddleware", - *(["silk.middleware.SilkyMiddleware"] if not RUNNING_TESTS else []), "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", @@ -182,3 +180,15 @@ DATABASES: dict[str, dict[str, str | Path | dict[str, str]]] = { }, }, } + +if not TESTING: + INSTALLED_APPS = [ + *INSTALLED_APPS, + "debug_toolbar", + "silk", + ] + MIDDLEWARE = [ + "debug_toolbar.middleware.DebugToolbarMiddleware", + "silk.middleware.SilkyMiddleware", + *MIDDLEWARE, + ] diff --git a/config/urls.py b/config/urls.py index 2202246..ae56148 100644 --- a/config/urls.py +++ b/config/urls.py @@ -15,12 +15,15 @@ urlpatterns: [URLPattern | URLResolver] = [ # type: ignore[assignment] path(route="", view=include("twitch.urls", namespace="twitch")), ] -if getattr(settings, "ENABLE_SILK", False): - urlpatterns += [path("silk/", include("silk.urls", namespace="silk"))] - # Serve media in development if settings.DEBUG: urlpatterns += static( settings.MEDIA_URL, document_root=settings.MEDIA_ROOT, ) + +if not settings.TESTING: + from debug_toolbar.toolbar import debug_toolbar_urls + + urlpatterns += [path("silk/", include("silk.urls", namespace="silk"))] + urlpatterns = [*urlpatterns, *debug_toolbar_urls()] diff --git a/pyproject.toml b/pyproject.toml index 7eb2f2d..d558a8c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,7 @@ dependencies = [ "gunicorn", "django-silk", "django-auto-prefetch", + "django-debug-toolbar", ] [dependency-groups]