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. Use your previous day's blog project or get hold of a fresh copy from here:

https://repl.it/@appbrewery/day-59-end.zip

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:

https://gist.github.com/angelabauer/97e23a7e6a044413ec3ed76456fd1c2e


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: You can use request.method to check which method triggered the route.

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

This is the result you're aiming for:

SOLUTION:

https://gist.github.com/angelabauer/bcb90f5060fe7204814da3249b069b7b


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/2.11.x/templates/#if

This is what you're aiming for:

SOLUTION:

https://gist.github.com/angelabauer/4db9f611e8b11a86021dc2eb6cdc61e7