Django has some very useful error pages built in that can help with a lot of debugging. Unfortunately sometimes you need to dig into the code a little more at run time to track down errors, etc.
Here are some additional methods for debugging Django…
Using pdb
pdb is part of the Python standard library. It allows you to set breakpoints, inspect objects, etc.
In Django, start your local server by invoking pdb
python -m pdb manage.py runserver
In your code, add this line right before the line you want to set a breakpoint on
import pdb; pdb.set_trace()
At the breakpoint, you will see the command line terminal stop and a (Pdb)
prompt will show up. From here you can enter an object’s name to inspect it. You can also run simple functions to see what they output.
For example:
(Pdb) request.is_ajax()
True
Just type c
to continue on from a breakpoint.