django-debug-toolbar not showing up

前端 未结 27 1625
谎友^
谎友^ 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 20:52

    I have the toolbar working just perfect. With this configurations:

    1. DEBUG = True
    2. INTERNAL_IPS = ('127.0.0.1', '192.168.0.1',)
    3. DEBUG_TOOLBAR_CONFIG = {'INTERCEPT_REDIRECTS': False,}
    4. The middleware is the first element in MIDDLEWARE_CLASSES:
    MIDDLEWARE_CLASSES = (
        'debug_toolbar.middleware.DebugToolbarMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
    )
    

    I hope it helps

    0 讨论(0)
  • 2020-11-30 20:52

    After many trial and error, this worked for me in Django=3.1 After writing all internal_ip, middleware, appending in url, put this code in settings.py at below

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

    Many of them suggested SHOW_TOOLBAR_CALLBACK, but in my case it only worked after added 'INSERT_BEFORE'

    0 讨论(0)
  • 2020-11-30 20:53

    If everything else is fine, it could also be that your template lacks an explicit closing <body> tag—

    Note: The debug toolbar will only display itself if the mimetype of the response is either text/html or application/xhtml+xml and contains a closing tag.

    0 讨论(0)
  • 2020-11-30 20:53

    I tried the configuration from pydanny's cookiecutter-django and it worked for me:

    # django-debug-toolbar
    MIDDLEWARE_CLASSES = Common.MIDDLEWARE_CLASSES + ('debug_toolbar.middleware.DebugToolbarMiddleware',)
    INSTALLED_APPS += ('debug_toolbar',)
    
    INTERNAL_IPS = ('127.0.0.1',)
    
    DEBUG_TOOLBAR_CONFIG = {
        'DISABLE_PANELS': [
            'debug_toolbar.panels.redirects.RedirectsPanel',
        ],
        'SHOW_TEMPLATE_CONTEXT': True,
    }
    # end django-debug-toolbar
    

    I just modified it by adding 'debug_toolbar.apps.DebugToolbarConfig' instead of 'debug_toolbar' as mentioned in the official django-debug-toolbar docs, as I'm using Django 1.7.

    0 讨论(0)
  • 2020-11-30 20:54

    In my case I just needed to remove the python compiled files (*.pyc)

    0 讨论(0)
  • 2020-11-30 20:56

    The current stable version 0.11.0 requires the following things to be true for the toolbar to be shown:

    Settings file:

    1. DEBUG = True
    2. INTERNAL_IPS to include your browser IP address, as opposed to the server address. If browsing locally this should be INTERNAL_IPS = ('127.0.0.1',). If browsing remotely just specify your public address.
    3. The debug_toolbar app to be installed i.e INSTALLED_APPS = (..., 'debug_toolbar',)
    4. The debug toolbar middleware class to be added i.e. MIDDLEWARE_CLASSES = ('debug_toolbar.middleware.DebugToolbarMiddleware', ...). It should be placed as early as possible in the list.

    Template files:

    1. Must be of type text/html
    2. Must have a closing </html> tag

    Static files:

    If you are serving static content make sure you collect the css, js and html by doing:

    ./manage.py collectstatic 
    


    Note on upcoming versions of django-debug-toolbar

    Newer, development versions have added defaults for settings points 2, 3 and 4 which makes life a bit simpler, however, as with any development version it has bugs. I found that the latest version from git resulted in an ImproperlyConfigured error when running through nginx/uwsgi.

    Either way, if you want to install the latest version from github run:

    pip install -e git+https://github.com/django-debug-toolbar/django-debug-toolbar.git#egg=django-debug-toolbar 
    

    You can also clone a specific commit by doing:

    pip install -e git+https://github.com/django-debug-toolbar/django-debug-toolbar.git@ba5af8f6fe7836eef0a0c85dd1e6d7418bc87f75#egg=django_debug_toolbar
    
    0 讨论(0)
提交回复
热议问题