《Flask web development》 3.3自定义错误页面
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
使用errorhandler装饰器,其中page_not_found(e)是继承与e的子类么?这个e代表的是什么意思?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
从定义来看,e是page_not_found的参数,e可能是Exception的实例, 可以用
type(e)来鉴别。
你试试不写e不就知道了吗,基础不扎实啊。。。
我也看到这个地方了。从这个中文文档上看到
这个小e可以是HTTP引发的错误,也可以是其他引起的错误(谢谢答主的提醒)。
e 就是一个 error 对象, 出错后的信息保存在这个变量里,类似于: