使用flasksecurity作为restapi的一部分

2024-04-26 13:15:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在构建一个带有flask安全性的restapi。幸运的是FlaskSecurity有很多视图和模板,在我的案例中不需要这些。显然,我无法通过用我自己的逻辑重新实现@app.route('/login')来覆盖它们。在

所以,简单的问题是,如何禁用flask security返回模板的所有视图?在


Tags: 视图模板restapiappflasklogin逻辑route
1条回答
网友
1楼 · 发布于 2024-04-26 13:15:54

我不认为您可以直接禁用,因为flask公开的API都没有禁用状态。您可以像下面的示例一样自定义视图:

以下是参考链接:Flask Security

security = Security(app, user_datastore)

# This processor is added to all templates
@security.context_processor
def security_context_processor():
    return dict(hello="world")

# This processor is added to only the register view
@security.register_context_processor
def security_register_processor():
    return dict(something="else")

希望有帮助。在

相关问题 更多 >