3

I am building BlogApp and I am trying to run Django-Debug-Toolbar BUT it is not showing. I have seen many answers BUT nothing worked for me.

I have installed it correctly according to the Documentation

I have added in installed apps , middlewares and urls and also collecstatic. BUT still not showing when i go to Browser.

settings.py

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,
    }

urls.py

if settings.DEBUG:
    import debug_toolbar
    urlpatterns += [
        path('__debug__/', include(debug_toolbar.urls)),
    ]

Any help would be Appreciated.

Thank You in Advance

3
  • I can imagine two things, first of all, can you get any static files in your project? Maybe the STATIC_URL is not configured correctly. A second assumption is the SHOW_TOOLBAR_CALLBACK variable inside the DEBUG_TOOLBAR_CONFIG, could you please change it to True? Commented Apr 21, 2021 at 17:53
  • I also did this. BUT still not showing. When i check into my server then it is correctly loading debug_toolbar/css/toolbar.css. AND static path is configured correctly. Commented Apr 22, 2021 at 1:59
  • By default, the HTML for the toolbar gets injected at the end of the body. If your templates do not contain a closing </body> tag, it will not get injected. Commented Dec 2, 2021 at 21:27

3 Answers 3

6

This code I placed at the bottom of settings and solved my problems:

settings.py

import mimetypes
mimetypes.add_type("application/javascript", ".js", True)

DEBUG_TOOLBAR_PATCH_SETTINGS = False

def show_toolbar(request):
    return True
    
DEBUG_TOOLBAR_CONFIG = {
'INTERCEPT_REDIRECTS': False,
"SHOW_TOOLBAR_CALLBACK": show_toolbar,
'INSERT_BEFORE': '</head>',
'INTERCEPT_REDIRECTS': False,
'RENDER_PANELS': True,
}

Another problem I have got it was no debug_tolbar/css files in my_project/static/ file. Collectstatic did not solve my problem. Solution: I have copied from: python3.8/site-packages/debug_toolbar/static/debug_toolbar/css/ to my_project/static/debug_toolbar/css/

Sign up to request clarification or add additional context in comments.

1 Comment

DEBUG_TOOLBAR_PATCH_SETTINGS is no longer used.
2

I had the same issue with application django debug toolbar In settings.py, everything is correctly, but the application did not showing in the browser. If you look by the inspect mode, you could see a javascript error because he sees it as text and not as js code.

Solution: In the registry Editor ("Ctrl+r" "regedit") find HKEY_CLASSES_ROOT.js then dubble click on the "Content Type" the "Value data" should be "text/javascript"

Then restart server "python manage.py runserver", remove cookies of your browser and that's all. At the worst restart your machine. enter image description here

1 Comment

Yea, this is what worked for me on Windows 10. Django 3.2. So annoying!
0

Try to add in your settings.py:

import socket
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[:-1] + "1" for ip in ips]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.