简体   繁体   English

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

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

Index page should be shown only to logged in users and redirect other users to landing page. 索引页面应仅显示给登录用户,并将其他用户重定向到登录页面。

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

So how could you refactor current_user in User.query.all() part? 那么,如何current_user in User.query.all()部分中重构current_user in User.query.all() Should I customize the @login_required somehow? 我应该以某种方式自定义@login_required吗? How have others dealt with this problem? 其他人如何处理这个问题?

Use current_user.is_authenticated property. 使用current_user.is_authenticated属性。 eg 例如

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