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

Lars
  • 1,234
  • 1
  • 8
  • 31
  • 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`? – Panos Angelopoulos Apr 21 '21 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.` – Lars Apr 22 '21 at 01:59
  • By default, the HTML for the toolbar gets injected at the end of the body. If your templates do not contain a closing `

    ` tag, it will not get injected.

    – Webucator Dec 02 '21 at 21:27

3 Answers3

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/

Robert
  • 81
  • 1
  • 3
0

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

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]
Mário Prada
  • 1,792
  • 1
  • 9
  • 13