Debugging Django with pdb

I just found that it is actually very easy to use Python’s builtin pdb debugger together with a Django application (using its debug server). It basically boils down to running the server with pdb instead of python:

In your code, set a breakpoint:

import pdb; pdb.set_trace()

Then run the server:

$ python -m pdb runserver [options]

On start, pdb will initialize on your console and wait for input. Execute “c” to continue the normal server procedure. Once you reach the breakpoint, pdb will interrupt and you can start debugging live in the console.

And we all love debugging, don’t we?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s