Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 16, 2021 03:23 pm GMT

Django Debug Toolbar - How to configure

Hello Coders,

This article explains how to add the popular Debug Toolbar to a Django project. For newcomers, the Django Debug Toolbar is a configurable set of panels that bumps various information about the current request/response when clicked. To make this article more useful, an open-source sample already configured is provided on Github (MIT License).

Thanks for reading! - Content provided by App Generator.

Django Debug Toolbar - Open-source sample provided by AppSeed.

Django Toolbar Set Up

Step #1 - Add django-debug-toolbar to project dependencies

# File: requirements.txt...django-debug-toolbar...

Or simply install via PIP

$ pip install django-debug-toolbar

Step #2 - Update project routes

# File core/urls.pyimport debug_toolbar   # <-- NEW                     from django.contrib import adminfrom django.urls import path, include  urlpatterns = [   ...   path('__debug__/', include(debug_toolbar.urls)),  # <-- NEW   ... ]

Step #3 - Update Settings

# File core/settings.py...from decouple import configfrom unipath import Pathimport dj_database_urlimport mimetypes                      # <-- NEWBASE_DIR = Path(__file__).parentINSTALLED_APPS = [   ...    'django.contrib.staticfiles',   'debug_toolbar',                   # <-- NEW   ...  ]MIDDLEWARE = [   ...   'django.middleware.clickjacking.XFrameOptionsMiddleware',   'debug_toolbar.middleware.DebugToolbarMiddleware',          # <-- NEW   ...]INTERNAL_IPS = [                                               # <-- NEW    '127.0.0.1',                                               # <-- NEW]                                                              # <-- NEWdef show_toolbar(request):                                     # <-- NEW    return True                                                # <-- NEW DEBUG_TOOLBAR_CONFIG = {                                       # <-- NEW    "SHOW_TOOLBAR_CALLBACK" : show_toolbar,                    # <-- NEW}                                                              # <-- NEWif DEBUG:                                                      # <-- NEW    import mimetypes                                           # <-- NEW              mimetypes.add_type("application/javascript", ".js", True)  # <-- NEW

Step #4 - Execute the migration

$ python manage.py makemigrations$ python manage.py migrate

Step #5 - Start the Django Project

$ python manage.py runserver

At this point, the Debug Toolbar should be visible on the right side for all pages.

Django Debug Toolbar - Open-source sample provided by AppSeed.

Thanks for reading! For more resources please access:


Original Link: https://dev.to/sm0ke/django-debug-toolbar-how-to-configure-2ap9

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To