简体   繁体   English

Django-Debug-Toolbar 未显示

[英]Django-Debug-Toolbar is not showing

I am building BlogApp and I am trying to run Django-Debug-Toolbar BUT it is not showing.我正在构建 BlogApp,我正在尝试运行Django-Debug-Toolbar但它没有显示。 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 .我已经添加了installed appsmiddlewaresurls以及collecstatic BUT still not showing when i go to Browser.但是当我 go 到浏览器时仍然没有显示。

settings.py设置.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网址.py

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

Any help would be Appreciated.任何帮助,将不胜感激。

Thank You in Advance先感谢您

This code I placed at the bottom of settings and solved my problems:我将这段代码放在设置的底部并解决了我的问题:

settings.py设置.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.我遇到的另一个问题是my_project/static/文件中没有debug_tolbar/css文件。 Collectstatic did not solve my problem. Collectstatic没有解决我的问题。 Solution: I have copied from: python3.8/site-packages/debug_toolbar/static/debug_toolbar/css/ to my_project/static/debug_toolbar/css/解决方案:我已经从: python3.8/site-packages/debug_toolbar/static/debug_toolbar/css/复制到my_project/static/debug_toolbar/css/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM