DEV Community

loading...

Django Debug Toolbar, not showing/appearing, Fix it & Bring it Back.

tipu profile image Borhan Tipu ・2 min read

Alt Text

Are you facing the problem with Django Debug Toolbar showing up?
I faced too…
Here I will show you how I fixed it….

Install Debug Toolbar…
For virtual env: pip install django-debug-toolbar
For Pipenv: pipenv install django-debug-toolbar

Link: https://pypi.org/project/django-debug-toolbar/
Docs: https://django-debug-toolbar.readthedocs.io/en/latest/

Go to settings.py and add to INSTALLED_APPS

INSTALLED_APPS = [
 # …
 'django.contrib.staticfiles',
 # … not for debug mode
 'debug_toolbar',
]
STATIC_URL = '/static/'
Enter fullscreen mode Exit fullscreen mode

The Debug Toolbar should have appeared only in Debug mode. So, the rest of the settings will be for DEBUG mode only.

# debug_toolbar moved here. 
if DEBUG:
    MIDDLEWARE += [
        'debug_toolbar.middleware.DebugToolbarMiddleware',
    ]
    INSTALLED_APPS += [
        'debug_toolbar',
    ]
    INTERNAL_IPS = ['127.0.0.1', ]

    # this is the main reason for not showing up the toolbar
    import mimetypes
    mimetypes.add_type("application/javascript", ".js", True)

    DEBUG_TOOLBAR_CONFIG = {
        'INTERCEPT_REDIRECTS': False,
    }
Enter fullscreen mode Exit fullscreen mode

Update your {project}/urls.py file.

from django.conf import settings
from django.urls import path, include
urlpatterns = [
  path("admin/", admin.site.urls),
]
# add debug toolbar in urlpatterns
if settings.DEBUG:
    import debug_toolbar
    urlpatterns += [
        path('__debug__/', include(debug_toolbar.urls)),
    ]
Enter fullscreen mode Exit fullscreen mode

The main reason for not showing up the toolbar is because of the javascript mime-types error when you connect the debug_toolbar
If the already added to your application then just add two lines of code in your settings.py file.

mimetypes
mimetypes.add_type("application/javascript", ".js", True)
Enter fullscreen mode Exit fullscreen mode

Now the debug toolbar should be visible in Debug mode.

Medium Link: Django Debug Toolbar Fix


If you need any help with Full-Stack Development with Django and Shopify, feel free to contact me anytime.
Visit: imtipu.me
Contact if you need any help with Django and Shopify
Skype: me@imtipu.me
Email: me@imtipu.me
Thanks!

Discussion (0)

pic
Editor guide