Flask Form Exercise
This is a Flask app with:
- An unfinished form, and
- An unfinished function
— both in the first route in the app.
The exercise is designed to give you hands-on practice with Flask-WTF after you've been introduced to the concepts in:
python-beginners Part 4: Forms in Flask
Get ready to do the exercise
- Download the zipped repo (this repo).
- Unzip and drag the unzipped folder into your Flask projects folder.
- Activate the virtualenv there.
- If you have not already done so, install both Flask-WTF and Flask-Bootstrap as instructed here.
- Open a new window in Atom and drag the flask-form-exercise-master folder into it.
Launch the restaurants app
In the Terminal, at the bash prompt ($), run the app:
python app.pyThe form doesn't work yet, but click the link to the restaurants page and you'll see a table listing local restaurants.
The goal of the exercise is for you to modify the file app.py so that the form will write complete data for new restaurants into the file restaurants.csv.
Complete the exercise
In the file app.py, there are two places where the comments say Exercise: — adding new code in those two places is all that needs to be done to complete the exercise and make the app work.
-
You will need several additional form controls to enter all the data needed for a restaurant. Figure out how to add them correctly. Note that all changes to the form will be done in app.py and NOT in the template.
-
You will need to add code in the function
index()to make submission of the form write a new record (a new line) into restaurants.csv. You'll need to open the file for appending (not reading) and usecsv.writer().
Good luck!