
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
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.
Example
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 settings.py −
INSTALLED_APPS = [ # ... 'debug_toolbar', 'myapp' ]
This will add the debug toolbar as an app in our project.
Next, in your middleware, add the following −
MIDDLEWARE = [ # ... 'debug_toolbar.middleware.DebugToolbarMiddleware', # ... ]
This is used to give access to the database.
Now, in urls.py 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 settings.py, add one more variable INTERNAL_IPS and mention localhost in it −
INTERNAL_IPS = [ # ... '127.0.0.1', # ... ]
This variable will define which URL should be debugged and on which debug should be shown.
Next, in views.py 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 urls.py 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> <html> <head> </head> <body> <h1>success</h1> </body> </html>
It will just render a simple message.
Output
You will see this toolbar at the right side of your screen on every URL endpoint −
- Related Articles
- How to add validation to your Django project?
- How to implement django-material in your Django project?
- How to add authorization to your Django website?
- How to add security to your Django website?
- How to add gradients to your project using CSS?
- How to add authentication to Django Website?
- How to add separator in a ToolBar with Java?
- How to add an UpdateView in Django?
- How to add a theme to your webpage using Bootswatch in a ReactJS project?
- How to add a Money field in Django?
- How to add Social Share buttons in Django?
- How to add a captcha in a Django website?
- How to add a text editor field in Django?
- How to add groups in Django using authentication system?
- How to Build your own website using Django in Python
