Screencast: Debugging with the Django Error Page

This is part 1 of a week long series of screencasts

Hey Everyone, I'm here to make a minor announcement. In the upcoming 7 days, I'm going to be releasing 5-7 screencasts on Django, mostly focused on debugging, and hopefully trying to throw in a couple of other useful ones that people might be interested it. This is my own way of helping people get ready for 1.0 and hopefully sharing some good tips on ways to use Django well. Please add you own comments and tips to the end of the posts! Please subscribe to my feed to get all of the screencasts (It'll be worth it!)

Also a big thanks to Simon Willison who's excellent debugging blog post got me started and interested in this stuff.

Screencast 1

The first in the series is going to be how to use the Django error page to it's fullest. It is a very useful piece of work (Thanks Wilson).

Setup

*Please install Django Command Extensions and The Werkzeug Debugger before you go on.

svn checkout http://django-command-extensions.googlecode.com/svn/trunk/ django-command-extensions
easy_install Werkzeug

Make sure that they are installed (on your PYTHONPATH) before continuing on.

Video

The full video can be downloaded here (18MB H.264 .mov)


Debugging with the Django error page from Eric Holscher on Vimeo.

Writeup

First off I fire up the debug server. Showing people how to use assert False. You use assert False when you just want to bring up a debug page to look at your context. It will bring up an AssertionError at the point where you put this code. assert False, foo brings up the error, showing whatever is in foo on the top of the error page.

The debug page is really useful because it contains a lot of useful information. It shows your entire ENVironment, including your GET, POST, COOKIES, PYTHONPATH, and lots of other good data. This information is really useful for debugging forms and session errors especially.

I then showed how to post your error to dpaste with one click in the error page. This is really handy for sharing your errors and tracebacks with people for them to help you debug your code.

"Part 2" of the screencast is about using the Werkzeug debugger for more debugging power. The command to run the Werkzeug debugger (with django-command-extensions) is:

./manage.py runserver_plus 67.207.139.9:8000 --settings settings_debug

with settings_debug.py being in the same file as your settings (and the current directory) containing:

from settings import *
DEBUG = True
INTERNAL_IPS = ['YOUR_IP']

whatismyip.com is a really handy utility for getting your external IP address. Then once you restart your debugging server, your error page should be the Werkzeug error page!

The Werkzeug error page is similiar to the django one, it has a traceback and all that good stuff. The killer feature however is that you can open up a python console at any of the places in your backtrace!

The dump() command inside the Werkzeug console is really handy. It will output a prettyprinted version of whatever you pass in. Allowing you to readily see what internal variables your object that you're debugging has.

Remember this is powerful! NEVER use this in production! People will have access to all your data!! It is a very powerful debugging tool, which is a double-edged sword.

PS: I hope you enjoyed me floundering in that later part. I thought it showed the value in the debugger so I left it in :)

Stay tuned daily at my feed for posts everyday up until Django 1.0! Cheers.


| Delicious Bookmark this on Delicious

Comments

1 Jason Emerick says...

Thanks for the screencast! I am looking forward to your future ones.

Posted at 3:17 a.m. on August 29, 2008

2 Brian Luft says...

Nice work Eric. The werkzeug debugger and the command extensions are definitely tools that can add efficiency to the development process. Looking forward to your other screencasts!

Posted at 2:34 p.m. on August 29, 2008

3 Andre Somov says...

When I need to debug Django I always switch into Eclipse/PyDev/Aptana. It is much more powerfull then the stuff you present.

Posted at 2:36 p.m. on August 29, 2008

4 Eric Holscher says...

@Andre: I was trying to show software that anyone can use. There are indeed some really nice (graphical) debuggers that I will be talking about later in the series.

Posted at 4:10 p.m. on August 29, 2008

5 kevin says...

@Andre Somov - I'd like to hear more about your Eclipse/PyDev/Aptana technique. Eric, maybe this is something you'll get into?

Posted at 5:32 p.m. on August 29, 2008

6 Pascal says...

Really interesting tools. Thanks for the screencast!

Posted at 1:38 p.m. on August 30, 2008

7 Paul Egges says...

Well I decided to try the Werkzeug debugger today, but the assert is dumping to the console, and I get a connection interrupted in the firefox window. So ....

I do like your presentation. The only question I had is there appears to be some blue text in the settings_debug file that I can not read.

Thanks,

Posted at 11:06 a.m. on November 21, 2008

8 Vitaly babiy says...

Hey Eric this is a great screen cast love the debug page with a interactive console.

Posted at 5:46 p.m. on November 23, 2008

9 cwxwwwxwwxwx says...

well, hi admin adn people nice forum indeed. how's life? hope it's introduce branch ;)

Posted at 9:49 a.m. on December 23, 2008

Comments support markdown

Comments are closed.

Comments have been close for this post.

About this post

Posted at 8:01 p.m. on August 28, 2008

Comments: 9

Tags: , , , , ,

Search Blog


Recent Posts

Enable setup.py test in your Django apps

4 days, 21 hours Ago (Comments: 1)

Migrating Django Test Fixtures Using South

3 weeks, 1 day Ago (Comments: 4)

A playground for Django Template tags and filters

1 month, 1 week Ago (Comments: 4)

EuroDjangoCon Talk: Testing Django

2 months Ago (Comments: 10)

Django's Summer of Code students announced!

2 months, 2 weeks Ago (Comments: 0)

More Posts...

Projects


Categories


Tag Cloud

abstract aggregator book community conventions dash debugging django djangocon doctest eurodjangocon fixtures idea ideas iowa lawrence mediaphormedia mentor pdb philosophy politics pony post-a-day practical project projects python review school screencast software ssh students talk template-tags templates testing testing-series testmaker tip tips tutorial umw unittest

Archive


I may not have gone where I intended to go, but I think I have ended up where I intended to be.

- Douglas Adams