Skip to content

Improve "Setting up URLconf" section in installation docs #1349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
  • Loading branch information
jdufresne committed Oct 1, 2020
commit ff4f603424fef8b791f995788c5abb9ebce9da88
12 changes: 6 additions & 6 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions example/urls.py
Original file line number Diff line number Diff line change
@@ -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))]