你如何调试Mako模板?

Nik*_*iah 36 python debugging templates mako jinja2

到目前为止,我发现当Mako模板编码不正确时,无法生成可用的回溯.

有没有办法调试模板除了迭代每行代码?

Tri*_*ych 40

Mako实际上提供了一种非常好的方法来跟踪模板中的错误:

from mako import exceptions

try:
    template = lookup.get_template(uri)
    print template.render()
except:
    print exceptions.html_error_template().render()
Run Code Online (Sandbox Code Playgroud)

  • 对于非HTML环境,还有[exceptions.text_error_template()](http://www.makotemplates.org/docs/usage.html#mako.exceptions.text_error_template).render(). (4认同)
  • 嗯,更好地避免全部除外. (3认同)