Skip to content

Commit bd365b8

Browse files
authored
Improve "Setting up URLconf" section in installation docs (#1349)
Remove the "if settings.DEBUG" guard. This guard is not necessary and leads to several edge cases in local development setups. This is not necessary as all views are guarded by the require_show_toolbar decorator which uses the SHOW_TOOLBAR_CALLBACK setting. This setting is already capable of enabling/disabling across the application when DEBUG is False. By default, when DEBUG is False, these views return a 404 response. By having the URLs always available, the MIDDLEWARE setting also doesn't need special handling when DEBUG is False, simplifing the overall configuration. An application should be able to reliably reverse URLs regardless of the status of DEBUG. Fixes #1035 Fixes #1043 Fixes #1332
1 parent cdf9754 commit bd365b8

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

docs/installation.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ If you're upgrading from a previous version, you should review the
4343
Setting up URLconf
4444
------------------
4545

46-
Add the Debug Toolbar's URLs to your project's URLconf as follows::
46+
Add the Debug Toolbar's URLs to your project's URLconf::
4747

48+
import debug_toolbar
4849
from django.conf import settings
4950
from django.urls import include, path
5051

51-
if settings.DEBUG:
52-
import debug_toolbar
53-
urlpatterns = [
54-
path('__debug__/', include(debug_toolbar.urls)),
55-
] + urlpatterns
52+
urlpatterns = [
53+
...
54+
path('__debug__/', include(debug_toolbar.urls)),
55+
]
5656

5757
This example uses the ``__debug__`` prefix, but you can use any prefix that
5858
doesn't clash with your application's URLs. Note the lack of quotes around

example/urls.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
from django.conf import settings
21
from django.contrib import admin
32
from django.urls import include, path
43
from django.views.generic import TemplateView
54

5+
import debug_toolbar
6+
67
urlpatterns = [
78
path("", TemplateView.as_view(template_name="index.html")),
89
path("jquery/", TemplateView.as_view(template_name="jquery/index.html")),
910
path("mootools/", TemplateView.as_view(template_name="mootools/index.html")),
1011
path("prototype/", TemplateView.as_view(template_name="prototype/index.html")),
1112
path("admin/", admin.site.urls),
13+
path("__debug__/", include(debug_toolbar.urls)),
1214
]
13-
14-
if settings.DEBUG:
15-
import debug_toolbar
16-
17-
urlpatterns += [path("__debug__/", include(debug_toolbar.urls))]

0 commit comments

Comments
 (0)