25

Sep

Filed in Code, Django |

One of the projects that I’ve been spending a lot of time with is the django-debug-toolbar. It was started off by Rob Hudson, and since has had huge amounts of support. While my fork is quite a ways off of Rob’s, they’re both quite useful in their own right. To clear up one very annoying detail: This project is in no way intended to replace profiling tools or complex debugging tools like pdb. It’s designed to give you quick access to general information to help debug or rough profile your web application.

I’ve been focusing on some of the hardcore features in panels, such as my SQL panel. MySQL users will find this especially useful, as not only do you get EXPLAIN support (provided for all backends which support it via EXPLAIN [statement]) but you also can get a printout of all of the available indexes and their columns. It makes figuring out what’s going on with your database a lot quicker.

I have also added full tracebacks for both database queries, and cache calls. Again, see the example, but it is another very helpful feature which can assist you in finding where stuff is happening within your codebase.

Among the many changes that have been getting thrown into my [somewhat unstable] fork, is a great design revamp by a character who goes by mape. It gives it a much more django-esque feel, and even has a lot of fancy “web 2.0″ (javascript) actions hooked in, such as inline filtering and sorting of tables.

To try out the project, it’s just a few simple actions to get it up and running:

  1. git clone git://github.com/dcramer/django-debug-toolbar.git
  2. Add django-debug-toolbar/ to your PYTHONPATH.
  3. Add debug_toolbar to your INSTALLED_APPS.
  4. Add 'debug_toolbar.middleware.DebugToolbarMiddleware' to your middleware. It should go after your Session, Auth, and GZip middleware, but can be placed before most others.
  5. Login via your superuser, or use the INTERNAL_IPS setting to allow your user to access it. Currently DEBUG must also be set to true.

I very much urge anyone who’s interested in the project to give feedback, as well as contribute if they so desire. There’s still a lot this project can achieve, and it most certainly can be a benefit in most web applications.

Just a note, if you’re using my branch, the template panel (as of writing) is non functional as I like to source everything, and it’s being revamped for Django+Jinja.

15 Responses to "Quick profiling your Django website with `debug_toolbar`"

Subscribe to this topic with RSS or get the Trackback URL
zuber (Sep 25th):

Great project! I was also trying to make a symfony-like debug toolbar for Django but you beat me to it.

I will definitely try it and give my feedback.

Nick (Sep 25th):

Great tool, thank you!

I have few minor problems with it. All my flash banners in iframe container displayed on top of visible layer, so debug-toolbar opened in full size was partly covered by my flash banners.

Also debug toolbar broke my jquery accordeon menu. All menu items were displayed at the same time instead of 1 active at a time.

I think first problem is more related to css styling (may be z-index:-1; will help). Second is more related to double jquery loading, I’ve seen very similar problem before.

Ole Morten (Sep 25th):

It looks fantastic, keep up the good work!

nono (Sep 25th):

@Nick,

Your on Linux? That’s a bug in flash or firefox causing that

veena (Sep 25th):

Great design, but it sends referer to google and some another server from your dev. Hmmm.

severb (Sep 25th):

It seems like the toolbar only appears on /admin pages. Any one knows why?

Ole Morten (Sep 25th):

@severb: Did you add your IP to the INTERNAL_IPS list? The toolbar will only appear if you’re logged in as a super user or if your ip is in INTERNAL_IPS.

Ole Morten (Sep 25th):

@veena: The jquery code seems to be loaded using the Google jsapi. Basically Google is hosting the jquery code. I guess the other request you see is to http://debug-django.appspot.com/js/jquery.tablesorter.js which the toolbar also pulls in.

Peter Bengtsson (Sep 25th):

AttributeError: ‘ProfilerDebugPanel’ object has no attribute ‘profiler’

blp330 (Sep 25th):

I found a possible bug in Middleware’s replace_insensitive function. You should use ‘rfind’ instead of ‘find’ in this line:

index = no_case.rfind(target.lower())

This is because if the dynamic html page inserts another html page in it (via ajax or other custom mechanisms), there will be two ” in it.

Thanks.

severb (Sep 26th):

@Ole Morten: Thanks. I’ve solve the issue by adding the “” tag in my templates.

severb (Sep 26th):

Sorry, no html allowed in comments. I was referring to the body tag.

veena (Sep 26th):

@Ole Morten yes, I think it’s not good idea to make that tool internet connection dependent. Any problem with package jquery and it’s plugin with toolbar?

Miles (Sep 26th):

Great,thank you!

David (Sep 26th):

I think we will allow jQuery’s paths to be a setting, and possibly include them with the package.

I’m going to write a middleware to just serve static files so we won’t have to worry about urlconf hijacking or any other issues.

Leave A Reply

 Username (*required)

 Email Address (*private)

 Website (*optional)

Note: Comments moderation may be active so there is no need to resubmit your comment.