-
poetry add -D django-debug-toolbar
ORpipenv install django-debug-toolbar --dev
-
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"]
- 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