Django Debug Toolbar is a very useful piece of django middleware which gives you a side panel displaying useful information about your app, including requests and sql queries.
As with any new piece of software in the hands of a novice, I had a few teething problems setting the toolbar up on my local machine. To remind me and to help others, I have distilled my morning’s work into the following succinct steps:
- Install django-debug-toolbar. I used
$ sudo easy_install django_debug_toolbar
though there are various methods. Just make sure the package ends up on your python path.
- Now we add the package to the MIDDLEWARE_CLASSES in your project settings.py:
MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.csrf.CsrfResponseMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware', )
The debug toolbar should be after any other middleware that encodes the response content, so it is best to place it last in the middleware sequence.
- We also add the package to INSTALLED_APPS in the project settings.py:
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'debug_toolbar', )
- Finally, make sure that the following appears in the project settings.py:
INTERNAL_IPS = ('127.0.0.1')
- Now fire up your project, and all being well, the django debug side panel should appear in the browser window. If this does not happen, the first thing to check is whether you have <body></body> tags in your html. If you switch to your project admin and the debug toolbar appears, this is most likely to be the issue. Other things to check are that the debug toolbar package is installed and on the python path:
>>> import sys >>> print sys.path