[英]How to get current user when implementing Python Flask-Security?
[英]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.