首页 > 解决方案 > 如何在烧瓶应用程序工厂中免除 csrf 令牌

问题描述

我正在使用烧瓶的应用程序工厂,我正在尝试豁免一条路线。如果我csrf.exempt(team_routes.team_bp)说它有效,但我只需要豁免team_bp.stat路线。我努力了csrf.exempt(team_routes.team_bp.team_stats)

csrf = CSRFProtect()

def create_app()
    ....
    csrf.init_app(app)
    with app.app_context():
        app.register_blueprint(team_route.team_bp)

我的team_route.py档案

 team_bp = Blueprint()

 @team_route.route('/stat/')
 @current_app.csrf.exempt
 def team_stats():

添加@current_app.csrf.exempt路线时出现以下错误Flask object has no attribute csrf。如果我将其添加csrf_token()到表单并提交它就可以了。但我想让stat路线豁免

标签: python-3.xflaskcsrf-token

解决方案


推荐阅读