从 Flask-Login 文档中,它描述了系统用户如何要求经过身份验证的用户模型来访问使用装饰器语法的方法:
from flask_login import login_required
@app.route("/settings")
@login_required
def settings():
pass
现在一切都很好,但我希望能够检查用户是否在方法中进行了身份验证,如下所示:
@app.route('/main/', methods=['GET', 'POST'])
main_route():
if request.method == 'GET':
if user_is_authenticated(): #Do the authentication here
#load authenticated /main/ html template etc.
pass
else:
#load unauthenticated /main/ html template etc.
pass
...
这样做的原因是因为它分解了 GET 和 POST 请求,而不是为经过身份验证的用户和未经身份验证的用户复制路由。
我怎样才能做到这一点?是否可以?