2016-10-12 3 views
0

색인 페이지는 로그인 한 사용자에게만 표시되고 다른 사용자는 방문 페이지로 리디렉션되어야합니다.어떻게 Flask-Security의 User.query.all()에서 current_user를 리팩터링 할 수 있습니까?

@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()? 어떻게 든 @login_required을 커스터마이징해야합니까? 다른 사람들이이 문제를 어떻게 처리합니까?

+0

User.is_logged_in 속성을 만들고 현재 사용자가 로그인했는지 확인하면 쿼리를 완전히 삭제할 수 있습니다. – Maarten

답변

3

current_user.is_authenticated 속성을 사용하십시오. 예 :

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