
1 gnozix 2018 年 6 月 6 日 .python 文件???没用过,不了解 |
2 ranleng 2018 年 6 月 6 日 .python 是啥? (而且这种情况应该上全部代码吧. 就三行 没上下文怎么知道哪出错了.. |
4 jhacker 2018 年 6 月 6 日 from . import errors 是不是写在文件最后的面? |
5 Codelike OP @Mrkon 是 py 文件。我试了一下。在根目录的__init__.py ,写上 @app.errorhandler(404) def page_not_found(e): return render_template('404.html'),404 是可以正常显示自定义错误界面的。 |
7 jhacker 2018 年 6 月 6 日 最好上传下项目,不然光你这样说没法定位问题 |
8 jhacker 2018 年 6 月 6 日 def _find_error_handler(self, e): """Return a registered error handler for an exception in this order: blueprint handler for a specific code, app handler for a specific code, blueprint handler for an exception class, app handler for an exception class, or ``None`` if a suitable handler is not found. """ exc_class, code = self._get_exc_class_and_code(type(e)) for name, c in ( (request.blueprint, code), (None, code), (request.blueprint, None), (None, None) ): handler_map = self.error_handler_spec.setdefault(name, {}).get(c) 看了下 Flask 相关的源码,貌似在 request.blueprint 这一步中本来是获取蓝图名称的,但是我调试后值一直为 None,也就是使用 app.errorhandler 进行装饰的函数 |
9 Mrkon 2018 年 6 月 6 日 在__init__.py 中创建了蓝本吗? main = Blueprint('main', __name__) |
12 jhacker 2018 年 6 月 7 日 哎呀又看错了,app_errorhandler 是全局的 |