How to add Django debug toolbar to your project?

Django toolbox is a debugging tool that is used to debug database queries, Django website loading speed, and many other things. Debug toolbar is very popular among developers and everyone is using it. So, let's dive into to see how to implement it.


Create an app with the name "myapp".

First, install the django-debug-toolbar

pip install django-debug-toolbar

Now, add 'debug_toolbar' to your INSTALLED_APPS in

   # ...

This will add the debug toolbar as an app in our project.

Next, in your middleware, add the following −

   # ...
   # ...

This is used to give access to the database.

Now, in of your project main directory, add the debug toolbar url −

import debug_toolbar
from django.conf import settings
from django.urls import include, path
urlpatterns = [
   path('__debug__/', include(debug_toolbar.urls)),
path('', include('myapp.urls'))

URL will define where all the debug reports should show and where the debug toolbar is needed to be hosted.

Now, in, add one more variable INTERNAL_IPS and mention localhost in it −

   # ...
   # ...

This variable will define which URL should be debugged and on which debug should be shown.

Next, in of app, add the following −

from django.shortcuts import render

# Create your views here.
def home(request):
   return render(request,"home.html")

It will render the frontend file.

Now, in of app, add the following −

from django.urls import path
from . import views
urlpatterns = [
   path('',views.home,name="home" ),

It will render the main view.

Next, create a folder in the app directory and name it templates and add home.html in it. In home.html, add the following simple code −

<!DOCTYPE html>


It will just render a simple message.


You will see this toolbar at the right side of your screen on every URL endpoint −

Updated on: 25-Aug-2021

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started