Now that we've seen how to get hold of the data entered into a form from our Flask server, it's time to apply this knowledge to our previous blog website.

1. Download the starting code from this lesson's resources. This is the same as the ending code for Day 59 with a small difference: the contact.html  has been simplified to make it easier to link the html form to your main.py. 


2. Add a "/form-entry" route in main.py to receive data from the form:

3. CHALLENGE: Update the code in contact.html and main.py so that you print the information the user has entered into the form and return a <h1> that says "Successfully sent your message". e.g.

SOLUTION


4. CHALLENGE: Combine the /contact route with /form-entry so that they are both under the route "/contact" but depending on which method (GET/POST) that triggered the route, handle it appropriately.

HINT 1: You'll need to modify both the action in the contact.html and your main.py

HINT 2: You can use request.method to check which method triggered the route.

https://flask.palletsprojects.com/en/2.3.x/quickstart/#http-methods

This is the result you're aiming for:

SOLUTION


5. CHALLENGE: Instead of returning a <h1> that says "Successfully sent message", update the contact.html file so that the <h1> on the contact.html file becomes "Successfully sent message".

HINT: https://jinja.palletsprojects.com/en/3.0.x/templates/#if

This is what you're aiming for:

SOLUTION