Hey there and welcome to Tokotoko Studio!

Check out our latest blog post:
Django tip: Debugging templates

Django tip: Debugging templates

using ipdb to get into your context

olof Sep 23 2012 Django

When debugging your Django code, the interactive python debugger is an invaluable tool. Whenever you want to take a look at what your code is really doing you can drop in the following line

import ipdb; ipdb.set_trace()

and then when you run the development server you'll be dropped into a debugging shell at that point. It makes it super easy to examine your data and step through your code.

However, that only works for your Python code, but sometimes you'll hit a problem in your templates where you can't understand what's wrong and really want to examine the context data. The following simple template tag let's you do just that

def ipdb(context, arg=None):
    import ipdb; ipdb.set_trace()
    return ''

You'll be dropped into a debugging shell where you have the context available, just like with the normal debugging. Just add this tag to your template tags and call {{ ipdb }} in your templates.

Comments powered by Disqus