Django - Add Debug Toolbar
Steps to add Debug Toolbar to a Django project
This page explains how to add Django Debug Toolbar to an existing Django project. For newcomers, the Django Debug Toolbar is a configurable set of panels that bumps various information about the current request/response when clicked.

How to install

Step #1 - Add django-debug-toolbar to project dependencies or install via PIP
1
# File: requirements.txt
2
...
3
django-debug-toolbar
4
...
Copied!
Or install via PIP
1
pip install django-debug-toolbar
Copied!
Step #2 - Update project routes
1
# File core/urls.py
2
​
3
import debug_toolbar # <-- NEW
4
​
5
from django.contrib import admin
6
from django.urls import path, include
7
​
8
urlpatterns = [
9
path('admin/', admin.site.urls),
10
11
path('__debug__/', include(debug_toolbar.urls)), # <-- NEW
12
13
path("", include("authentication.urls")),
14
path("", include("app.urls"))
15
]
16
​
Copied!
Step #3 - Update Settings
1
# File core/settings.py
2
...
3
from decouple import config
4
from unipath import Path
5
import dj_database_url
6
​
7
import mimetypes # <-- NEW
8
​
9
​
10
BASE_DIR = Path(__file__).parent
11
​
12
INSTALLED_APPS = [
13
'django.contrib.sessions',
14
'django.contrib.messages',
15
'django.contrib.staticfiles',
16
'debug_toolbar', # <-- NEW
17
'app'
18
]
19
​
20
MIDDLEWARE = [
21
'django.contrib.auth.middleware.AuthenticationMiddleware',
22
'django.contrib.messages.middleware.MessageMiddleware',
23
'django.middleware.clickjacking.XFrameOptionsMiddleware',
24
'debug_toolbar.middleware.DebugToolbarMiddleware', # <-- NEW
25
]
26
​
27
INTERNAL_IPS = [ # <-- NEW
28
'127.0.0.1', # <-- NEW
29
] # <-- NEW
30
​
31
def show_toolbar(request): # <-- NEW
32
return True # <-- NEW
33
​
34
DEBUG_TOOLBAR_CONFIG = { # <-- NEW
35
"SHOW_TOOLBAR_CALLBACK" : show_toolbar, # <-- NEW
36
} # <-- NEW
37
​
38
if DEBUG: # <-- NEW
39
import mimetypes # <-- NEW
40
mimetypes.add_type("application/javascript", ".js", True) # <-- NEW
Copied!
​
Step #4 - Execute the migration
1
$ python manage.py makemigrations
2
$ python manage.py migrate
Copied!
​
Step #5 - Start the app (the debug toolbar should be visible)
1
$ python manage.py runserver
Copied!
At this point, the Debug Toolbar should be visible on the right side for all pages.
Django Debug Toolbar - Soft UI Dashboard.

Resources

Last modified 3mo ago
Copy link