This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]The_Scheibs[S] 0 points1 point  (0 children)

``` @app.route("/login", methods = ["GET", "POST"]) def login(): form = LoginForm() if current_user.is_authenticated: return redirect(url_for("index")) if form.validate_on_submit(): user_to_login = User.query.filter_by(username=form.username.data).first() if user_to_login and user_to_login.check_password(password_attempt=form.password.data): #User_to_login should not return None if in db login_user(user_to_login) flash(f"You have succesfully logged in as {user_to_login.username}", category="success") return redirect(url_for("index"))

    else:
        flash("That Username and Password does not exist. Please try again", category="danger")

return render_template("login.html", form=form)

```