繁体   English   中英

如何在Flask-Security的User.query.all()中重构current_user?

[英]How could you refactor current_user in User.query.all() in Flask-Security?

索引页面应仅显示给登录用户,并将其他用户重定向到登录页面。

@app.route('/')
def index():
    if current_user in User.query.all():
        return render_template('index.html')
    else:
        return render_template('landing.html')

那么,如何current_user in User.query.all()部分中重构current_user in User.query.all() 我应该以某种方式自定义@login_required吗? 其他人如何处理这个问题?

使用current_user.is_authenticated属性。 例如

if current_user.is_authenticated:
    return render_template('index.html')
else:
    return render_template('landing.html')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM