Block 63: Flask: Forms & POST Requests
Handle user input from HTML forms.
Concepts
- HTML form with method='POST'
- request.form dictionary
- GET vs POST distinction
- Redirecting after form submission: redirect()
Code Examples
See exercise below.
Exercise
Build a BMI calculator: HTML form takes weight and height, Flask computes and displays BMI. Add basic validation: check that values are numeric before computing.
Homework
What is the POST/Redirect/GET pattern and why does it prevent form resubmission?