How can I make django show exceptions to functions called in templates?

Django has (usually great) behavior for turning exceptions into patterns into blank lines. So if I do {{object.fn_which_throws_exception}}, I just get an empty string. But sometimes I would like to know something about the exception: is there a way to make django real or register the data of such exceptions?

+3
source share
2 answers

If you use runserver, you can use pdb to execute the code.

Add import pdb; pdb.set_trace()over the problematic code. Go to the URL in question in your browser, and pdb should pause execution and let you go through the code line by line.

http://docs.python.org/library/pdb.html

+2

, , DEBUG TEMPLATE_DEBUG True.

, django-sentry . , DEBUG=True. , , .

EDIT: , . try... except :

def fn_which_throws_exception():
    import sys
    try:
        # code that might raise exception
    except:
        return sys.exc_info()
0

All Articles