I'm working on a web application for a gym. I created a login system to restrict access to some fields in the application. My question is the following, I want to know how to redirect the user to the current page after logging in, for example:
User is on the "Home" page, clicks to login, after logging in return to the home page...
Just as if he is on the "Nearby gyms" page, after logging in he returns to the same "Nearby gyms" page...
I hope it was clear.
I tried this, but it's giving me an error:
@app.route("/login", methods=["GET", "POST"])
def login():
login_form = Login_User()
if not current_user.is_authenticated:
if login_form.validate_on_submit():
user = User.query.filter_by(email=login_form.email.data).first()
if user and check_password_hash(user.password_hash, login_form.password.data):
login_user(user)
return redirect(request.referrer)
else:
flash("Wrong password or Email!")
return redirect(url_for('login'))
return render_template("login.html", login_form=login_form)
else:
flash("You are already logged in!")
return redirect(request.referrer)
When I click to login, after registering the page stops working:
What can I do to solve this?
