Flask-Mako在使用过程中,如果出错,无法定位出错的地方,这是很多mako的使用者放弃使用的原因,我搜索了一下百度,找到了debug的方法:
https://stackoverflow.com/questions/390409/how-do-you-debug-mako-templates 中ford的回答
在flask项目文件config.py中,添加
MAKO_TRANSLATE_EXCEPTIONS = False
然后在视图函数中,做一些改动:
from flask_mako import render_template
from mako import exceptions
@app.route('/', methods = ['Get','POST'])
def index():
try:
return render_template('index.html')
except:
return exceptions.html_error_template().render()
这样,当出错的时候,就能看到很详细的信息了!
最后友情提醒一下,mako中的标签%和后面的英文绝对不要有空格,比如<%include file="xx"/>不会报错,但是<% include file="xx"/>就会报错了,原因就是%和include之间不能有空格!!!切记