Skip to content

Instantly share code, notes, and snippets.

@kevinbowen777
Last active April 24, 2022 05:51
Show Gist options
  • Save kevinbowen777/6ee3b3f66fac58326919782452f2007b to your computer and use it in GitHub Desktop.
Save kevinbowen777/6ee3b3f66fac58326919782452f2007b to your computer and use it in GitHub Desktop.
Install django-debug-toolbar

Install django-debug-toolbar


  1. poetry add -D django-debug-toolbar OR pipenv install django-debug-toolbar --dev

  2. There are three separate configurations to set in our config/settings.py file:

  • INSTALLED_APPS
  • Middleware
  • INTERNAL_IPS

2a. Add to INSTALLED_APPS

# config/settings.py
INSTALLED_APPS = [
    'django.contrib.admin',
    ...
    'django.contrib.sites',

    # Third-party
    'debug_toolbar', # new

    # Local
    'accounts',
    'pages',
    'books',
]

2b. Add to MIDDLEWARE section:

# config/settings.py
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    ...
    'debug_toolbar.middleware.DebugToolbarMiddleware', # new
]

2c. Add the following lines at the bottom of config/settings.py.:

# django-debug-toolbar
# Use the following in Docker only:
# import socket
# hostname, _, ips = socket.gethostbyname_ex(socket.gethostname()) 
# INTERNAL_IPS = [ip[:-1] + "1" for ip in ips]                                  
# The following is for use locally:                                             
INTERNAL_IPS = ["127.0.0.1"]
  1. Update URLconf:
# Add to top of file
from django.conf import settings
...
# config/urls.py
if settings.DEBUG: # new
    import debug_toolbar  # noqa: F401
    urlpatterns = [
        path('__debug__/', include(debug_toolbar.urls)),
    ] + urlpatterns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment