Skip to content

Commit a0f8e1e

Browse files
committed
Create urls module and remove import package from docs.
By creating a urls module, devs can include the urls with a string path to the urls, include('debug_toolbar.urls').
1 parent ffa60c2 commit a0f8e1e

File tree

6 files changed

+11
-12
lines changed

6 files changed

+11
-12
lines changed

debug_toolbar/toolbar.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ def is_toolbar_request(cls, request):
143143
"""
144144
Determine if the request is for a DebugToolbar view.
145145
"""
146+
from debug_toolbar.urls import app_name
147+
146148
# The primary caller of this function is in the middleware which may
147149
# not have resolver_match set.
148150
try:
@@ -152,7 +154,3 @@ def is_toolbar_request(cls, request):
152154
except Resolver404:
153155
return False
154156
return resolver_match.namespaces and resolver_match.namespaces[-1] == app_name
155-
156-
157-
app_name = "djdt"
158-
urlpatterns = DebugToolbar.get_urls()

debug_toolbar/urls.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from debug_toolbar.toolbar import DebugToolbar
2+
3+
app_name = "djdt"
4+
urlpatterns = DebugToolbar.get_urls()

docs/changes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Next version
1111
usages before ``enable_instrumentation`` is called.
1212
* Add check ``W006`` to warn that the toolbar is incompatible with
1313
``TEMPLATES`` settings configurations with ``APP_DIRS`` set to ``False``.
14+
* Create ``urls`` module and update documentation to no longer require
15+
importing the toolbar package.
1416

1517

1618
3.2.2 (2021-08-14)

docs/installation.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ Add django-debug-toolbar's URLs to your project's URLconf:
7979

8080
.. code-block:: python
8181
82-
import debug_toolbar
8382
from django.urls import include, path
8483
8584
urlpatterns = [
8685
# ...
87-
path('__debug__/', include(debug_toolbar.urls)),
86+
path('__debug__/', include('debug_toolbar.urls')),
8887
]
8988
9089
This example uses the ``__debug__`` prefix, but you can use any prefix that

example/urls.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
from django.urls import include, path
33
from django.views.generic import TemplateView
44

5-
import debug_toolbar
6-
75
urlpatterns = [
86
path("", TemplateView.as_view(template_name="index.html")),
97
path("jquery/", TemplateView.as_view(template_name="jquery/index.html")),
108
path("mootools/", TemplateView.as_view(template_name="mootools/index.html")),
119
path("prototype/", TemplateView.as_view(template_name="prototype/index.html")),
1210
path("admin/", admin.site.urls),
13-
path("__debug__/", include(debug_toolbar.urls)),
11+
path("__debug__/", include("debug_toolbar.urls")),
1412
]

tests/urls.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from django.contrib.auth.views import LoginView
33
from django.urls import include, path, re_path
44

5-
import debug_toolbar
6-
75
from . import views
86
from .models import NonAsciiRepr
97

@@ -25,5 +23,5 @@
2523
path("redirect/", views.redirect_view),
2624
path("login_without_redirect/", LoginView.as_view(redirect_field_name=None)),
2725
path("admin/", admin.site.urls),
28-
path("__debug__/", include(debug_toolbar.urls)),
26+
path("__debug__/", include("debug_toolbar.urls")),
2927
]

0 commit comments

Comments
 (0)