From ff4f603424fef8b791f995788c5abb9ebce9da88 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 27 Sep 2020 08:57:56 -0700 Subject: [PATCH] Improve "Setting up URLconf" section in installation docs 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 --- docs/installation.rst | 12 ++++++------ example/urls.py | 9 +++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index b3ebbf76a..a1272b1d0 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -43,16 +43,16 @@ If you're upgrading from a previous version, you should review the Setting up URLconf ------------------ -Add the Debug Toolbar's URLs to your project's URLconf as follows:: +Add the Debug Toolbar's URLs to your project's URLconf:: + import debug_toolbar from django.conf import settings from django.urls import include, path - if settings.DEBUG: - import debug_toolbar - urlpatterns = [ - path('__debug__/', include(debug_toolbar.urls)), - ] + urlpatterns + urlpatterns = [ + ... + path('__debug__/', include(debug_toolbar.urls)), + ] This example uses the ``__debug__`` prefix, but you can use any prefix that doesn't clash with your application's URLs. Note the lack of quotes around diff --git a/example/urls.py b/example/urls.py index e263c3068..a190deaaa 100644 --- a/example/urls.py +++ b/example/urls.py @@ -1,17 +1,14 @@ -from django.conf import settings from django.contrib import admin from django.urls import include, path from django.views.generic import TemplateView +import debug_toolbar + urlpatterns = [ path("", TemplateView.as_view(template_name="index.html")), path("jquery/", TemplateView.as_view(template_name="jquery/index.html")), path("mootools/", TemplateView.as_view(template_name="mootools/index.html")), path("prototype/", TemplateView.as_view(template_name="prototype/index.html")), path("admin/", admin.site.urls), + path("__debug__/", include(debug_toolbar.urls)), ] - -if settings.DEBUG: - import debug_toolbar - - urlpatterns += [path("__debug__/", include(debug_toolbar.urls))]