We saw that when using a basic HTML form, we can use the request object from Flask to access the key-value pairs that were entered into the form when the POST request was made.
With WTForms, it's even easier to get hold of the form data. All you have to do is to tap into the
<form_object>.<form_field>.data
e.g.
But one thing we should check before printing the field data is whether if the form has been submitted (POST request) or if it's GET request when the form is being rendered.
Previously we used
if request.method == "POST"
Now, we're simply going to check the return value of validate_on_submit()
which will be True
if validation was successful after the user submitted the form, or False
if it failed.
CHALLENGE: Update the /login
route in main.py so that if the form was submitted and validated and their credentials matched the following:
email: admin@email.com
password: 12345678
then show them the success.html page.
Otherwise show them the denied.html page
e.g.
SOLUTION:
https://gist.github.com/angelabauer/20ba20298ee26c957f36176291de9d69