0

I have a login route like this

@app.route('/login/<int:user_id>)
def login(user_id):
    if some_condition:
        return redirect(url_for('dashboard', user_id=user_id)
    return render_template('login.html')

The route for the dashboard goes like this

@app.route('/dashboard/<int:user_id>)
@login_required
def dashboard(user_id):
    # some code...
    return render_template('dashboard.html')

Ideally, you shouldn't be able to access the dashboard without logging in. Hence, the use of @login_required decorator. When a user manually types in the address bar /dashboard/2 where 2 represents the user_id. If the user is not logged in, dashboard redirects to login. The following line causes that behaviour.

login_manager.login_view = 'login'

login refers to the name of the login route function. How do i pass the user_id, in this case 2 to login_manager.login_view = 'login'

Kun.tito
  • 165
  • 1
  • 7
  • I don't know who flagged it, but I guess these are not the answers you want. – fatih Jan 05 '23 at 13:21
  • @fatih No, they aren't. can i unflag a question? – Kun.tito Jan 05 '23 at 17:49
  • Let me answer you as a comment on your question. Please do not send your `id` as request parameter. It will help you if you examine the `current_user` function of `Flask`. – fatih Jan 05 '23 at 19:33

0 Answers0