3

I have a new project and I'm trying to set up Django Debug Toolbar. First I tried the quick setup, which only involves adding 'debug_toolbar' to my list of installed apps. With this, the debug toolbar showed up when I went to my root URL, but it did not work for my app urls/views. I should not that presently, my root URL is not linked to a view, so it was showing a django error page.

Since the quick start didn't work, I went with the explicit setup. I updated my settings file:

DEBUG_TOOLBAR_PATCH_SETTINGS = False

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
)

And updated my project-level urls.py:

if settings.DEBUG: # make sure the toolbar is above ?CKeditor and FeinCMS
    import debug_toolbar
    urlpatterns += patterns('',
        url(r'^__debug__/', include(debug_toolbar.urls)),
    )

But now it doesn't show up anywhere.

In my app view, I've added a {% debug %} to the template. The template debug output does seem to indicate that the debug toolbar middleware has been loaded:

 'debug_toolbar': <module 'debug_toolbar' from '/home/joseph/.virtualenvs/myproject/local/lib/python2.7/site-packages/debug_toolbar/__init__.pyc'>,
 'debug_toolbar.collections': None,
 'debug_toolbar.compat': <module 'debug_toolbar.compat' from '/home/joseph/.virtualenvs/myproject/local/lib/python2.7/site-packages/debug_toolbar/compat.pyc'>,
 'debug_toolbar.django': None,
 'debug_toolbar.importlib': None,
 'debug_toolbar.middleware': <module 'debug_toolbar.middleware' from '/home/joseph/.virtualenvs/myproject/local/lib/python2.7/site-packages/debug_toolbar/middleware.pyc'>,

I'm not sure why this isn't working. My django version is 1.8 and my debug toolbar version is 1.3.2.

Joseph
  • 12,678
  • 19
  • 76
  • 115

1 Answers1

4

My solution to this problem was to add <body></body> tags to the template.

I got it from the "Tips" section on django-debug-toolbar site.

The Debug Toolbar will only display when DEBUG = True in your project’s settings. It will also only display if the mimetype of the response is either text/html or application/xhtml+xml and contains a closing </body> tag.

Source: django-debug-toolbar.readthedocs.io/en/stable/tips.html

If the toolbar works on index page (or any other) but not on another, missing body tags are probably the reason.

Emanuel Lindström
  • 1,607
  • 16
  • 25