Skip to content

Commit 0abf601

Browse files
committed
Add option to enable Django Debug Toolbar for local development
This commit introduces the ability to enable the Django Debug Toolbar for local development. The toolbar can be activated by setting the `ENABLE_DJANGO_DEBUG_TOOLBAR` environment variable to `True`. Changes include: - Adding the necessary configuration in `settings/base.py` - Updating `urls.py` to include debug toolbar URLs - Adding `django-debug-toolbar` to development dependencies in `pyproject.toml` and `uv.lock`
1 parent 437e069 commit 0abf601

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

backend/pycon/settings/base.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,27 @@
144144
# "qinspect.middleware.QueryInspectMiddleware",
145145
]
146146

147+
# Django Debug Toolbar
148+
149+
ENABLE_DJANGO_DEBUG_TOOLBAR: bool = env.bool(
150+
"ENABLE_DJANGO_DEBUG_TOOLBAR", default=False
151+
)
152+
153+
154+
if ENABLE_DJANGO_DEBUG_TOOLBAR:
155+
INSTALLED_APPS.append("debug_toolbar")
156+
157+
MIDDLEWARE.insert(0, "debug_toolbar.middleware.DebugToolbarMiddleware")
158+
159+
DEBUG_TOOLBAR_CONFIG = {
160+
"SHOW_TOOLBAR_CALLBACK": lambda _: DEBUG,
161+
"SHOW_COLLAPSED": True,
162+
}
163+
164+
INTERNAL_IPS = [
165+
"127.0.0.1",
166+
]
167+
147168
ROOT_URLCONF = "pycon.urls"
148169

149170
FORM_RENDERER = "custom_admin.template_backends.FormRenderer"

backend/pycon/urls.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
path("", include("notifications.urls")),
3535
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
3636

37+
38+
if settings.DEBUG:
39+
if settings.ENABLE_DJANGO_DEBUG_TOOLBAR:
40+
from debug_toolbar.toolbar import debug_toolbar_urls
41+
42+
urlpatterns += debug_toolbar_urls()
43+
44+
3745
urlpatterns = urlpatterns + [
3846
path("", include(wagtail_urls)),
3947
]

backend/pyproject.toml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,21 @@ name = "Python Italia"
114114
text = "MIT"
115115

116116
[dependency-groups]
117-
dev = ["mypy<2.0.0,>=1.2.0", "pytest==7.4.3", "pytest-cov==4.1.0", "pytest-django==4.6.0", "factory-boy==3.3.0", "pdbpp<1.0.0,>=0.10.3", "requests-mock<2.0.0,>=1.11.0", "pytest-mock<4.0.0,>=3.12.0", "pytest-cache<2.0,>=1.0", "time-machine<3.0.0,>=2.13.0", "libcst<2.0.0,>=1.1.0", "wagtail-factories<5.0.0,>=4.1.0", "pytest-xdist>=3.5.0", "websockets>=12.0", "typer>=0.12.3"]
117+
dev = [
118+
"mypy<2.0.0,>=1.2.0",
119+
"pytest==7.4.3",
120+
"pytest-cov==4.1.0",
121+
"pytest-django==4.6.0",
122+
"factory-boy==3.3.0",
123+
"pdbpp<1.0.0,>=0.10.3",
124+
"requests-mock<2.0.0,>=1.11.0",
125+
"pytest-mock<4.0.0,>=3.12.0",
126+
"pytest-cache<2.0,>=1.0",
127+
"time-machine<3.0.0,>=2.13.0",
128+
"libcst<2.0.0,>=1.1.0",
129+
"wagtail-factories<5.0.0,>=4.1.0",
130+
"pytest-xdist>=3.5.0",
131+
"websockets>=12.0",
132+
"typer>=0.12.3",
133+
"django-debug-toolbar>=5.0.1",
134+
]

backend/uv.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)