Wednesday, March 30, 2011

How do you debug Mako templates?

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?

Edit: Per the comments, it seems switching to Jinja2 might be the best solution.

From stackoverflow
  • I break them down into pieces, and then reassemble the pieces when I've found the problem.

    Not good, but it's really hard to tell what went wrong in a big, complex template.

  • 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()
    

0 comments:

Post a Comment