【发布时间】:2021-01-13 01:50:41
【问题描述】:
如何添加自定义 HTTP 错误?据我了解,6XX 和 7XX 类中的错误代码可用于此目的,但 Flask 不允许我处理这些错误,因为它说 this(601) 不是公认的 HTTP 错误。
编辑: 这是正确的代码:-
from werkzeug.exceptions import HTTPException
@errors.errorhandler(HTTPException)
def error_601(HTTPException):
return render_template('errors/601.html'), 601
class No_results_found(HTTPException):
code = 601
description = '<p>No_results_found.</p>'
errors.register_error_handler(No_results_found, error_601)
【问题讨论】: