How do you debug Mako templates?

Nikhil Chelliah picture Nikhil Chelliah · Dec 24, 2008 · Viewed 9.8k times · Source

So far I've found it impossible to produce usable tracebacks when Mako templates aren't coded correctly.

Is there any way to debug templates besides iterating for every line of code?

Answer

Triptych picture Triptych · Feb 11, 2009

Mako actually provides a VERY nice way to track down errors in a template:

from mako import exceptions

try:
    template = lookup.get_template(uri)
    print template.render()
except:
    print exceptions.html_error_template().render()