Bottle.py 附带一个导入来处理抛出的 HTTPErrors 和路由到函数。
首先,文档声称我可以(几个例子也是如此):
from bottle import error
@error(500)
def custom500(error):
return 'my custom message'
但是,当导入此语句时,错误未解决,但在运行应用程序时会忽略这一点,只是将我引导到通用错误页面。
我找到了解决这个问题的方法:
from bottle import Bottle
main = Bottle()
@Bottle.error(main, 500)
def custom500(error):
return 'my custom message'
但是这段代码阻止了我将我的错误全部嵌入到一个单独的模块中,以控制如果我将它们保存在我的 main.py 模块中会出现的问题,因为第一个参数必须是一个瓶子实例。
所以我的问题:
有没有其他人经历过这个?
为什么错误似乎只在我的情况下解决(我从pip install bottle 安装)?
有没有一种无缝的方法可以将我的错误路由从单独的 python 模块导入到主应用程序中?