MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Django Debug Toolbar0%
Study Materials
Django for Backend DevelopmentProgress 0%
1.1Installing Django & Environment Setup1.2Django Project Structure1.3Creating First Django App
9.1Unit Testing9.2Debugging Tips9.3Django Debug Toolbar
HomeTutorialsDjango for Backend DevelopmentDjango Debug Toolbar
Deploying to Heroku

Django Debug Toolbar

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

Diagnosing performance issues in Django requires visibility into what occurs under the hood on every HTTP request. The Django Debug Toolbar (DDT) is a configurable sidebar that attaches to rendered HTML pages during local development, displaying detailed metrics on SQL queries executed, cache hits/misses, HTTP headers, template rendering times, and memory consumption.


1. Installing and Configuring Django Debug Toolbar

1pip install django-debug-toolbar

Configuration in settings.py:

1# config/settings.py
2 
3# 1. Add to INSTALLED_APPS
4INSTALLED_APPS = [
5 # ...
6 "debug_toolbar",
7]
8 
9# 2. Add middleware (Place early in pipeline, just after GZip/Security)
10MIDDLEWARE = [
11 "debug_toolbar.middleware.DebugToolbarMiddleware",
12 # ... other middlewares
13]
14 
15# 3. Configure Internal IPs (ensures toolbar only shows on localhost)
16INTERNAL_IPS = [
17 "127.0.0.1",
18 "localhost",
19]

Configuration in config/urls.py:

1from django.conf import settings
2from django.urls import path, include
3 
4urlpatterns = [
5 # ... project URLs
6]
7 
8# Only include debug toolbar routes in development mode
9if settings.DEBUG:
10 import debug_toolbar
11 urlpatterns = [
12 path("__debug__/", include(debug_toolbar.urls)),
13 ] + urlpatterns

2. The SQL Panel: Catching N+1 Queries

The most powerful panel in DDT is the SQL Panel:

Visual Architecture Blueprint
┌─────────────────────────────────────────────────────────────┐
│ Django Debug Toolbar - SQL Queries                          │
├─────────────────────────────────────────────────────────────┤
│ Total Queries: 104  |  Time: 182.40ms  |  Duplicates: 101    │
├─────────────────────────────────────────────────────────────┤
│ 1. SELECT * FROM enterprise_articles (1.2ms)                │
│ 2. SELECT * FROM auth_user WHERE id = 1 (0.8ms) [DUPLICATE] │
│ 3. SELECT * FROM auth_user WHERE id = 1 (0.9ms) [DUPLICATE] │
│ 4. SELECT * FROM auth_user WHERE id = 1 (0.8ms) [DUPLICATE] │
│ ...                                                         │
└─────────────────────────────────────────────────────────────┘
  • Duplicate Queries Badge: Highlights duplicate queries in red/magenta, instantly alerting you to an N+1 query bug!
  • EXPLAIN and TRACE: Clicking EXPLAIN on any query shows the database execution plan, showing if a full table scan occurred due to a missing index.

3. Other Core Debug Panels

  • Time Panel: Breaks down CPU execution time between Python code, template compilation, and database queries.
  • Templates Panel: Lists every template and partial (base.html, _card.html) rendered on the page, along with context variables passed to each.
  • Cache Panel: Shows cache hits, misses, and keys accessed during the request.
  • Signals Panel: Displays all signals dispatched and the receivers triggered.
  • Headers Panel: Inspects incoming client headers and outgoing response headers.

4. Enabling Debug Toolbar Inside Docker

When running Django inside Docker, request.META['REMOTE_ADDR'] is the Docker bridge IP (e.g. 172.18.0.1), which causes INTERNAL_IPS = ["127.0.0.1"] to fail. Use this callback to enable DDT inside Docker containers:

1# config/settings.py
2def show_toolbar(request):
3 return DEBUG and not request.is_ajax()
4 
5DEBUG_TOOLBAR_CONFIG = {
6 "SHOW_TOOLBAR_CALLBACK": show_toolbar,
7}

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What is the primary purpose of the Django Debug Toolbar?
Question 2
Why must the Debug Toolbar URL patterns and middleware be guarded behind if settings.DEBUG?
Question 3
What visual indicator does the SQL panel display when an N+1 query issue exists?
Question 4
Why is INTERNAL_IPS = ["127.0.0.1"] required for the Debug Toolbar to display?
Question 5
What information does clicking "EXPLAIN" on an SQL query in the toolbar reveal?
Next Lesson

Deploying to Heroku

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Debugging TipsDeploying to Heroku

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Django for Backend Development with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext