vendredi 18 décembre 2020

Flask request.args.get('next') never return redirect to next_page

im following one tutorial on youtube, i have been succesfull up untill this point. I have a problem with redirecting to next page.

Here is the code:

@app.route('/login', methods = ["GET", "POST"])
def login():
    if current_user.is_authenticated:
        flash("You are already logged in", "danger")
        return redirect(url_for("home"))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get("next")
            if next_page:
                return redirect(next_page)
            else:
                return redirect(url_for("home"))
        else:
            flash("User doesn't exist", "danger")
    return render_template("login.html",title="Login", form=form)

So the point is, to redirect the user to his account page. However when i test this, it always redirects me to the home page instead... And i dont see why... Can anybody help a noob?

Aucun commentaire:

Enregistrer un commentaire