Skip to content

Commit 1aa2ba0

Browse files
authored
Add Django debug toolbar for local development (#4339)
1 parent 437e069 commit 1aa2ba0

File tree

6 files changed

+69
-66
lines changed

6 files changed

+69
-66
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ STRIPE_SECRET_API_KEY=
4343

4444
Adding the secret keys after the `=` symbol.
4545

46+
## Enabling Django Debug Toolbar
47+
48+
To enable the Django Debug Toolbar, set the `ENABLE_DJANGO_DEBUG_TOOLBAR` variable to `true` in your `.env` file:
49+
50+
```text
51+
ENABLE_DJANGO_DEBUG_TOOLBAR=true
52+
```
53+
4654
## External repos
4755

4856
Repos used by this project are in separate repositories.

backend/README.md

Lines changed: 0 additions & 65 deletions
This file was deleted.

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
path("", include("notifications.urls")),
3535
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
3636

37+
38+
if settings.DEBUG and settings.ENABLE_DJANGO_DEBUG_TOOLBAR:
39+
from debug_toolbar.toolbar import debug_toolbar_urls
40+
41+
urlpatterns += debug_toolbar_urls()
42+
43+
3744
urlpatterns = urlpatterns + [
3845
path("", include(wagtail_urls)),
3946
]

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)