在我的python flask应用程序中,我定义了对应于api端点的蓝图路由,
# Submit Agreement (Insert or Update)
@bp.route('submitAgreement', methods=['POST'])
@auth.login_required
def submitAgreement():
#...code...
# Get Existing Agreement
@bp.route('fetchAgreement', methods=['POST'])
@auth.login_required
def fetchAgreement():
#...code...
我需要定义一个公共路由传递或过滤器,它将在执行代码之前执行授权。如果url包含参数,则需要进行授权 id=..
,检查该id是否属于登录用户。
有没有办法用python中的代码定义自定义的“方面”或过滤器?
1条答案
按热度按时间goqiplq21#
flask 提供了一个
@app.before_request
室内装修设计师你可以代替
app
对于bp
将定义的函数仅应用于蓝图。