Django: 4 steps to add “django-debug-toolbar”

Grassroot Engineer
2 min readSep 26, 2024

--

https://django-debug-toolbar.readthedocs.io/en/latest/index.html

This tool will help to investigate ORM query command in Django, so let’s get to the point on how to install in Djang project.

  1. Install lib of django-debug-toolbar~=3.2.4 in project.
  • Add django-debug-toolbar~=3.2.4 in requirements.in
  • Run this docker command (to compile .in file) or if not use docker can add django-debug-toolbar==3.2.4 to requiremenst.txt directly.
docker-compose exec django sh -c "pip install pip-tools && pip-compile"

2. Rebuild Docker image again like this command.

docker-compose build django

3. Add app in settings.py

    INSTALLED_APPS += [
'debug_toolbar',
]

MIDDLEWARE += [
'debug_toolbar.middleware.DebugToolbarMiddleware',
]

DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': lambda _request: DEBUG
}

4. Add config this 2 lines in urls.py

import debug_toolbar

path('__debug__/', include(debug_toolbar.urls)),
import debug_toolbar

TESTING = len(sys.argv) > 1 and sys.argv[1] == 'test'

if settings.DEBUG or TESTING:
urlpatterns += [
path('__debug__/', include(debug_toolbar.urls)),
] + static(
settings.STATIC_URL, document_root=settings.STATIC_ROOT
) + static(
settings.MEDIA_URL, document_root=settings.MEDIA_ROOT
)

5. Done and now can show Django debug toolbar in Browsable API.

Very good !!!

Ref:
https://www.youtube.com/watch?v=H-vLUoXKKIs

If you think it’s useful for you, just clap your hands 👏 to be encouraged me.

GRASSROOT ENGINEER 😘

--

--

Grassroot Engineer
Grassroot Engineer

Written by Grassroot Engineer

ATM engineer who is interested in CODING and believe in EFFORT. — https://grassrootengineer.com

No responses yet