If you ever get to the point that you need to optimize your website, I recommend you check out the Django-Debug-Toolbar. It provides a pretty amazing set of features that can be used to trace slow pieces of code, investigate SQL queries, debug headers, requests, and even trace Django templates.

There are a lot of instructions around the web on how to get it up and running - but none of them seemed to work for me. Here is what I had to do:

First thing first, install the django debug toolbar using pip:

pip install django-debug-toolbar

After the toolbar is installed, update your urls.py file to support the debug urls.

if settings.DEBUG:
	import debug_toolbar
	urlpatterns += patterns('',
		url(r'^__debug__/', include(debug_toolbar.urls)),

Next, you need to add the specific options to your settings.py file. You can read more about the different options here, but I just like to added them all:

	INSTALLED_APPS += ( 'debug_toolbar',)
	MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)

Make sure they’re available in DEBUG mode only.

Finally, collect your static files to get the css, js and html that come with it package

./manage.py collectstatic

You should now see the debug tool bar on the left side of your site.

Couple last notes:

  • to run collectstatic you need to have the following variables set
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
  • to view the html in the debug-tool-bar, you probably need the following code at the bottom of your main urls.py file
if settings.DEBUG:
	urlpatterns += patterns('',
		(r'^media/(?P<path>.*)$', 'django.views.static.serve',
			{'document_root': settings.MEDIA_ROOT}),
	urlpatterns += patterns('',
		(r'^static/(?P<path>.*)$', 'django.views.static.serve',
			{'document_root': settings.STATIC_ROOT}),