How do you debug Mako templates?

后端 未结 6 1708
星月不相逢
星月不相逢 2021-01-30 21:15

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 ever

6条回答
  •  有刺的猬
    2021-01-30 21:52

    Using flask_mako, I find it's easier to skip over the TemplateError generation and just pass up the exception. I.e. in flask_mako.py, comment out the part that makes the TemplateError and just do a raise:

    def _render(template, context, app):
     """Renders the template and fires the signal"""
    app.update_template_context(context)
    try:
        rv = template.render(**context)
        template_rendered.send(app, template=template, context=context)
        return rv
    except:
        #translated = TemplateError(template)                                                                                                                 
        #raise translated                                                                                                                                     
        raise
    

    }

    Then you'll see a regular python exception that caused the problem along with line numbers in the template.

提交回复
热议问题