Django and Oscar

Django Debug Toolbar

Published 2021-02-12. Last modified 2021-03-27.
Time to read: 1 minutes.

This page is part of the django collection.

Django Debug Toolbar

The Django Debug Toolbar is a very useful tool, and is easy to set up. This is a good video on YouTube about installing Django Debug Toolbar.

The Django Debug Toolbar is only needed for development, so it should be installed after separate settings for dev have been established.

I put the Django Debug Toolbar settings in settings/dev.py. Below is my complete settings/dev.py for Frobshop; the only line not associated with Django Debug Toolbar is the one starting with EMAIL_BACKEND:

settings/dev.py
from .base import *
DEBUG = True
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
DEBUG_TOOLBAR_CONFIG = { 'JQUERY_URL': '', }
INSTALLED_APPS += [ 'debug_toolbar', ]
INTERNAL_IPS = [ '127.0.0.1', ]
MIDDLEWARE += [ 'debug_toolbar.middleware.DebugToolbarMiddleware', ]

The only other changes required in order for the Django Debug Toolbar to operate are:

  1. Add the following to urls.py:
    urls.py
    import debug_toolbar
    urlpatterns = [ path('__debug__/', include(debug_toolbar.urls)), ]
  2. Add the .dev qualifier to frobshop.settings in manage.py:
    manage.py
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'frobshop.settings.dev')

Now install Django Debug Toolbar and update requirements.txt:

Shell
(aw) $ python -m pip install django-debug-toolbar
(aw) $ pip freeze > requirements.txt


* indicates a required field.

Please select the following to receive Mike Slinn’s newsletter:

You can unsubscribe at any time by clicking the link in the footer of emails.

Mike Slinn uses Mailchimp as his marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp’s privacy practices.