Python 如何在Flask Security中重构user.query.all()中的当前用户?
索引页应仅显示给登录用户,并将其他用户重定向到登录页Python 如何在Flask Security中重构user.query.all()中的当前用户?,python,flask,flask-security,Python,Flask,Flask Security,索引页应仅显示给登录用户,并将其他用户重定向到登录页 @app.route('/') def index(): if current_user in User.query.all(): return render_template('index.html') else: return render_template('landing.html') 那么,如何在user.query.all()中重构当前用户?我是否应该以某种方式自定义所需的@log
@app.route('/')
def index():
if current_user in User.query.all():
return render_template('index.html')
else:
return render_template('landing.html')
那么,如何在user.query.all()中重构当前用户?我是否应该以某种方式自定义所需的
@login\u
?其他人是如何处理此问题的?使用当前\u用户。是否通过了\u身份验证属性。e、 g
if current_user.is_authenticated:
return render_template('index.html')
else:
return render_template('landing.html')
使用当前用户。是否经过身份验证属性。e、 g
if current_user.is_authenticated:
return render_template('index.html')
else:
return render_template('landing.html')
您可以创建User.is_logged_属性并检查当前用户是否已登录。使您完全不用进行查询。您可以创建User.is\u logged\u属性并检查当前用户是否已登录。使您完全不必进行查询。