Django trick: getting a readable traceback

When working/debugging with Django, there may be cases where you get the full (debug) HTML error template. For example, when using pdb on client code that invokes a django view.

It's really hard to get the actual error from such a template (without a browser). The following code snippet may be of help in these cases:

import lxml.html  # this should be standard in your python toolchain :)

lxml.html.document_fromstring(res.content).get_element_by_id("traceback_area").text_content()

This will produce a more readable traceback without all the html / css cruft.

Last updated April 18, 2013, 4:35 p.m. | filed under django | debugging pdb django traceback
comments powered by Disqus