Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Debug Toolbar shows at root URL, but not in app URL

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.

like image 591
Joseph Avatar asked Jan 31 '26 02:01

Joseph


1 Answers

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.

like image 155
Emanuel Lindström Avatar answered Feb 01 '26 19:02

Emanuel Lindström



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!