我正在寻找一种方法来捕捉mako运行时错误使用瓶子。在
使用以下代码捕获python中的运行时错误:
# main.py
from lib import errors
import bottle
app = bottle.app()
app.error_handler = errors.handler
...
# lib/errors.py
from bottle import mako_template as template
def custom500(error):
return template('error/500')
handler = {
500: custom500
}
这是完美的,因为异常会变成500个内部服务器错误。在
我想用类似的方式捕捉mako运行时的错误,有人知道如何实现这一点吗?在
您想要捕获
mako.exceptions.SyntaxException
。在这个代码适用于我:
编辑:根据您的评论,这里有一些关于如何在全局范围内安装的提示。安装一个bottle plugin,它将函数包装在mako.exceptions.SyntaxException试试布洛克。在
大致如下:
^{pr2}$相关问题 更多 >
编程相关推荐