0

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? Should I customize the @login_required somehow? How have others dealt with this problem?

nalzok
  • 14,965
  • 21
  • 72
  • 139
hooligan
  • 15
  • 6
  • You could create a User.is_logged_in property and check if your current user is logged in. saves you from making the query altogether. – Maarten Oct 12 '16 at 10:57

1 Answers1

3

Use current_user.is_authenticated property. e.g

if current_user.is_authenticated:
    return render_template('index.html')
else:
    return render_template('landing.html')
pjcunningham
  • 7,676
  • 1
  • 36
  • 49