So, let's create a simple /login route that will add a LoginForm instance to the application context. Then, we'll render the login.html template:
login_manager.login_view = 'login'
@app.route('/login') # URL
def login(): # name of the view
form = LoginForm() # create a LoginForm instance
return render_template('login.html', form=form) # render the login.html template with a form parameter
Now, you can navigate to http://localhost:5000/login. You should see the following form:
However, at the moment, clicking on the form will raise an error because POST requests are, by default, not allowed on our view. To make them allowed, we have to modify the app.route decorator on our view so that we can add the allowed methods:
@app.route('/login', methods=["GET", "POST"])
def login():
Now that we are able to make POSTs to this view, we can handle them. Here are the steps we will follow:
- Validate the form...