django-debug-toolbar not showing up

前端 未结 27 1628
谎友^
谎友^ 2020-11-30 20:12

I looked at other questions and can\'t figure it out...

I did the following to install django-debug-toolbar:

  1. pip install django-debug-toolbar
相关标签:
27条回答
  • 2020-11-30 21:17

    An addition to previous answers:

    if the toolbar doesn't show up, but it loads in the html (check your site html in a browser, scroll down)

    the issue can be that debug toolbar static files are not found (you can also see this in your site's access logs then, e.g. 404 errors for /static/debug_toolbar/js/toolbar.js)

    It can be fixed the following way then (examples for nginx and apache):

    nginx config:

    location ~* ^/static/debug_toolbar/.+.(ico|css|js)$ {
        root [path to your python site-packages here]/site-packages/debug_toolbar;
    }
    

    apache config:

    Alias /static/debug_toolbar [path to your python site-packages here]/site-packages/debug_toolbar/static/debug_toolbar
    

    Or:

    manage.py collectstatic
    

    more on collectstatic here: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#collectstatic

    Or manualy move debug_toolbar folder of debug_toolbar static files to your set static files folder

    0 讨论(0)
  • 2020-11-30 21:17

    django 1.8.5:

    I had to add the following to the project url.py file to get the debug toolbar display. After that debug tool bar is displayed.

     from django.conf.urls import include
     from django.conf.urls import patterns
     from django.conf import settings
    
    
      if settings.DEBUG:
          import debug_toolbar
          urlpatterns += patterns('',
                  url(r'^__debug__/', include(debug_toolbar.urls)),
                  )
    

    django 1.10: and higher:

    from django.conf.urls import include, url
    from django.conf.urls import patterns
    from django.conf import settings
    
    
    if settings.DEBUG:
    
      import debug_toolbar
      urlpatterns =[
             url(r'^__debug__/', include(debug_toolbar.urls)),
             ] + urlpatterns
    

    Also don't forget to include the debug_toolbar to your middleware. The Debug Toolbar is mostly implemented in a middleware. Enable it in your settings module as follows: (django newer versions)


    MIDDLEWARE = [
    # ...
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    #
    

    Old-style middleware:(need to have _CLASSES keywork in the Middleware)

    MIDDLEWARE_CLASSES = [
    # ...
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    # ...
    ]
    
    0 讨论(0)
  • 2020-11-30 21:18

    In my case, it was another problem that hasn't been mentioned here yet: I had GZipMiddleware in my list of middlewares.

    As the automatic configuration of debug toolbar puts the debug toolbar's middleware at the top, it only gets the "see" the gzipped HTML, to which it can't add the toolbar.

    I removed GZipMiddleware in my development settings. Setting up the debug toolbar's configuration manually and placing the middleware after GZip's should also work.

    0 讨论(0)
提交回复
热议问题