Django Debug Toolbar: Helper for django developers

Adi Ramadhan
2 min readMay 22, 2023

--

Showing History, versions, time, settings, and other helpful information for django developer.
Official docs django-debug-toolbar

django with django-debug-toolbar

Project Structure:

Step 1: Preparation, Create Django Project, Inital Migration
create virtualenv: virtualenv venv
start virtualenv: venv/Scripts/activate
install Django and django-debug-toolbar in virtualenv: pip install django==4.2 django-debug-toolbar
Create Django: django-admin startproject myproject
Go to myproject folder: cd myproject
Initial Migration: python manage.py migrate

Step 2: Create Django Apps
Create apps: python manage.py startapp myapp

Step 3: Project Setting: Register Apps and Django Debug Toolbar, Set Templates Folder (myproject/settings.py)
Make sure static is configured, add myapp and debug_toolbar in INSTALLED_APPS, setup TEMPLATES folder, add INTERNAL_IPS

...

INSTALLED_APPS = [
...
'django.contrib.staticfiles', #make sure this is configured in settings

'myapp', #updated
'debug_toolbar', #updated

]

...

TEMPLATES = [
...
'DIRS': [Path(BASE_DIR, 'templates')], #updated
...
]

...

STATIC_URL = 'static/' #make sure this is configured in settings

...

#updated
INTERNAL_IPS = [
# ...
"127.0.0.1", #updated
# ...
]

Step 4: Add Templates Folder and Files
Create templates folder in root
Create index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World</title>
</head>
<body>
<h1>Hello World.</h1>
<p>This is html page!</p>
</body>
</html>

Step 5: Create View in myapp/views.py

from django.shortcuts import render

# Create your views here.
def index(request):
return render(request, 'index.html', {})

Step 6: Setup URLs in myapp and myproject Folder

Create myapp/urls.py


from django.urls import path
from . import views


urlpatterns = [
path('', views.index, name = "index"), #updated

]

Update myproject/urls.py

from django.urls import path, include #updated

urlpatterns = [
path('', include('myapp.urls')), #updated
path('__debug__/', include('debug_toolbar.urls')), #updated
]

Step 7: Run Server and Test
Run Server: python manage.py runserver
Access: http://127.0.0.1:8000

django debug toolbar shown in django apps

--

--

Adi Ramadhan
Adi Ramadhan

No responses yet