Home

Aug. 24, 2016, 1 min read

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 manage.py 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?

spock_despair