Cannot get django-debug-toolbar to appear

你。 提交于 2019-12-04 00:42:31

问题


No matter what I do, I simply cannot get django-debug-toolbar to appear. I've tried everything suggested in every answer on this question.

  • I have DEBUG=True in my settings
  • I have django.contrib.staticfiles and debug_toolbar in INSTALLED_APPS
  • I have 'debug_toolbar.middleware.DebugToolbarMiddleware' high up in MIDDLEWARE_CLASSES
  • I have INTERNAL_IPS = () in my settings
  • I tried adding print("IP Address for debug-toolbar: " + request.META['REMOTE_ADDR']) in a view, and it printed IP Address for debug-toolbar: 127.0.0.1
  • I have a closing </body></html> in my template
  • I have run pip install django-debug-toolbar in my virtualenv, without any issues
  • I have run python manage.py collectstatic and there is a debug_toolbar directory in my static files

When I run the app, I see no request in the console for any URLs containing django_debug_toolbar, so I suspect it's the application not being loaded.

I don't see any failed requests in the developer console, either.

I've read the django-debug-toolbar installation docs and am out of ideas.

Does anyone have any suggestions for debugging? I'm running OSX and Django 1.7. The curious thing is that debug-toolbar WAS appearing just fine - I think I've made some tweak that caused it to vanish, but I don't know what.

UPDATE: I've even tried adding this in my settings file, which is supposed to force the toolbar to appear:

def show_toolbar(request):
    return True
SHOW_TOOLBAR_CALLBACK = show_toolbar

But it doesn't help.

I've also tried throwing a deliberate exception in my view, so that I can check DEBUG is on and all the settings are as above. They are, and still no toolbar!

UPDATE 2: When I set INTERNAL_IPS=('127.0.0.1',), I start to see debug-toolbar requests in the console, but no toolbar on the page.

And the following HTML appears in my page - so the toolbar is there, but it's not visible because it's got display=none set all over it:


回答1:


All of the divs with display: none; are in fact behaving properly. They won't change to display: block; until you actually click on them in the toolbar itself.

The button used to toggle the toolbar is the div with an id="djDebugToolbarHandle". As you can see in your console, this button has a top position of 2310px. What this means is that it is rendering, but it is just way down off the page.

Try typing the following in the console to reset its position:

document.getElementById('djDebugToolbarHandle').style.top="30px";



回答2:


I had the same problem but managed to fix it following dvl's comment on this page. Here is a summary of the fix:

In settings.py

if DEBUG:
    MIDDLEWARE += (
        'debug_toolbar.middleware.DebugToolbarMiddleware',
    )
    INSTALLED_APPS += (
        'debug_toolbar',
    )
    INTERNAL_IPS = ('127.0.0.1', )
    DEBUG_TOOLBAR_CONFIG = {
        'INTERCEPT_REDIRECTS': False,
    }

In the project urls.py, add this url pattern to the end:

from django.conf import settings

if settings.DEBUG:
    import debug_toolbar

    urlpatterns += [
        url(r'^__debug__/', include(debug_toolbar.urls)),
    ]



回答3:


Some information for news users as me, when dev on virtual or remote machine

Add this ligne in a views.py file

print("IP Address for debug-toolbar: " + request.META['REMOTE_ADDR'])

When the views is call, you can see the client IP in the shell

You have to add this IP the settings.py file INTERNAL_IPS = ('IP')




回答4:


One reason why django-debug-toolbar might appear but not appear correctly, (items stuck in "Loading") is if manage.py collectstatic has not been run. Just thought I'd post that here in case it helps someone.




回答5:


I had the same problem. Changing the finder module in my settings.py worked for me:

STATICFILES_FINDERS = (
    #'django.contrib.staticfiles.finders.FileSystemFinder', #THIS BREAKES debug_toolbar
    'django.contrib.staticfiles.finders.AppDirectoriesFinder', #THIS WORKS
)

Make sure to clean the browser cache after this change.

But after this, Django gave me error messages during collectstatic, due to this issue. I solved creating two configurations in my settings.py:

class Production(Base):
   DEBUG = False
   STATICFILES_FINDERS = (
      'django.contrib.staticfiles.finders.FileSystemFinder',
   )

class Develop(Base):
   DEBUG = True
   STATICFILES_FINDERS = (
      'django.contrib.staticfiles.finders.AppDirectoriesFinder',
   )

I hope it helps.



来源:https://stackoverflow.com/questions/28984239/cannot-get-django-debug-toolbar-to-appear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!