Login Form and login route - csemanish12/flask_blog GitHub Wiki

login form

We want our user to enter their email and password so that they can login to our system. We need a login form for that. We will user WTForms for login as well. Lets create a class LoginForm in our forms.py

blog/forms.py

.
.
class LoginForm(FlaskForm):
    email = StringField('Email', validators=[DataRequired(), Email()])
    password = PasswordField('Password', validators=[DataRequired()])
    submit = SubmitField('Login')

Login Route

Now that we have login form, we need a login route. Lets update our routes.py to add login route

blog/routes.py

.
from blog.forms import LoginForm
.
.
@app.route("/login", methods=["GET", "POST"])
def login():
    form = LoginForm()
    return render_template('login.html', form=form)
  • Don't forget to import LoginForm from our forms.py

Implementation can be found over this commit