Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 999
Nikhil Avatar asked Dec 23 '08 23:12

Nikhil


3 Answers

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()
like image 162
Kenan Banks Avatar answered Oct 17 '22 21:10

Kenan Banks


Looking at the Flask-Mako source, I found an undocumented configuration parameter called MAKO_TRANSLATE_EXCEPTIONS.

Set this to False in your Flask app config and you'll get nice exceptions bubbling up from the template. This accomplishes the same thing as @Mariano suggested, without needing to edit the source. Apparently, this parameter was added after Mariano's answer.

like image 43
ford Avatar answered Oct 17 '22 21:10

ford


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.

like image 1
S.Lott Avatar answered Oct 17 '22 23:10

S.Lott