|      1gnozix      2018-06-06 14:33:12 +08:00 .python 文件???没用过,不了解 | 
|  |      2ranleng      2018-06-06 14:34:56 +08:00 .python 是啥? (而且这种情况应该上全部代码吧. 就三行 没上下文怎么知道哪出错了.. | 
|  |      4jhacker      2018-06-06 14:46:31 +08:00 from . import errors  是不是写在文件最后的面? | 
|  |      5Codelike OP @Mrkon 是 py 文件。我试了一下。在根目录的__init__.py ,写上 @app.errorhandler(404) def page_not_found(e): return render_template('404.html'),404 是可以正常显示自定义错误界面的。 | 
|  |      7jhacker      2018-06-06 15:36:18 +08:00 最好上传下项目,不然光你这样说没法定位问题 | 
|  |      8jhacker      2018-06-06 16:02:39 +08:00 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 进行装饰的函数 | 
|      9Mrkon      2018-06-06 16:05:46 +08:00 在__init__.py 中创建了蓝本吗? main = Blueprint('main', __name__) | 
|  |      11jhacker      2018-06-07 08:32:21 +08:00 @Codelike  昨天也有点懵, 其实 app_errorhandler 是对于蓝图起作用的,errorhandler 是对于全局的异常处理 | 
|  |      12jhacker      2018-06-07 08:34:19 +08:00 哎呀又看错了,app_errorhandler 是全局的 |