为所有路由定义公共路由传递或筛选器

cwxwcias  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(309)

在我的python flask应用程序中,我定义了对应于api端点的蓝图路由,

  1. # Submit Agreement (Insert or Update)
  2. @bp.route('submitAgreement', methods=['POST'])
  3. @auth.login_required
  4. def submitAgreement():
  5. #...code...
  6. # Get Existing Agreement
  7. @bp.route('fetchAgreement', methods=['POST'])
  8. @auth.login_required
  9. def fetchAgreement():
  10. #...code...

我需要定义一个公共路由传递或过滤器,它将在执行代码之前执行授权。如果url包含参数,则需要进行授权 id=.. ,检查该id是否属于登录用户。
有没有办法用python中的代码定义自定义的“方面”或过滤器?

goqiplq2

goqiplq21#

flask 提供了一个 @app.before_request 室内装修设计师
你可以代替 app 对于 bp 将定义的函数仅应用于蓝图。

相关问题