Python 如何从不同的文件调用flask中的错误处理程序?

Python 如何从不同的文件调用flask中的错误处理程序?,python,flask,error-handling,Python,Flask,Error Handling,在app.py中运行我的flask应用程序时,索引页应该抛出一个错误,该错误应该由error\u advice.py中定义的flask错误处理程序捕获。相反,它没有得到处理 app.py from flask import * from flask_cors import * from error_advice import * app = Flask(__name__) app.register_blueprint(advice) # this is where it throws err

app.py
中运行我的flask应用程序时,索引页应该抛出一个错误,该错误应该由
error\u advice.py
中定义的flask错误处理程序捕获。相反,它没有得到处理

app.py

from flask import *
from flask_cors import *

from error_advice import *
app = Flask(__name__)
app.register_blueprint(advice)

# this is where it throws error
@app.route('/', methods=['GET'])
def index():
    return str(1/0)

if __name__ == '__main__':
    CORS(app)  # lets other programs consume app
    app.debug = True
    app.run()
错误通知.py

from flask import Blueprint
from logger import *
advice = Blueprint('advice', __name__)


# error advice
# supposed to go here when error occurs, but doesn't

@advice.errorhandler(Exception) 
def handle_error(e: Exception):
    message = str(e)
    return {f"{type(e).__name__}": message}, 400
问题:为什么它不在
error\u advice
中调用
handle\u error
,我如何解决这个问题

Python版本:3.8 烧瓶版本:1.1.2