Creating views

The login and registration views will create our form objects and pass them to the templates. After the LoginForm validates the user's credentials, we will use Flask-Login to actually log the user in.

In the auth/ controller, we will find the login view, as shown in the following code:

...from flask_login import login_user, logout_user...@auth_blueprint.route('/login', methods=['GET', 'POST'])@oid.loginhandlerdef login():    form = LoginForm()    ...    if form.validate_on_submit():        user = User.query.filter_by(        login_user(user,        ...        flash("You have been logged in.", category="success")        return redirect(url_for('main.index'))    ...    return render_template('login.html' ...

Get Mastering Flask Web Development - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.