Skip to main content

Debugging Django Template Tags

Here's a cool bit of code snippet that I found from the web (original post here). I'm recording it here for my own easy reference without having to google it all the time. It describes a simple technique to debug Django templates using the python debugger - pdb.

def pdb(element):
    import pdb; pdb.set_trace()
    return element
Now, inside a template you can do
{{ template_var|pdb }}
and enter a pdb session (given you're running the local development server) where you can inspect element to your heart's content.

It's a very nice way to see what's happened to your object when it arrives at the template.