Mike Slinn
Mike Slinn

Django Debug Toolbar

Published 2021-02-12. Last modified 2021-03-27.

This article is categorized under Django.

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