Survey
For this lab, you’ll implement a web app that enables a user to
- fill out a form, a la Google Forms, the results of which are saved to a comma-separated-value (CSV) file on the server, and
- view a table of all of the submissions received, a la Google Sheets,
a la the below.


Getting Started
Here’s how to download this problem’s distribution code. Log into CS50 Sandbox or CS50 IDE and then, in a terminal window, execute each of the below.
- Execute
cdto ensure that you’re in your home directory. - Execute
wget http://cdn.cs50.net/hbs/2020/spring/labs/6/survey.zipto download a (compressed) ZIP file with this problem’s distribution. - Execute
unzip survey.zipto uncompress that file. - Execute
rm survey.zipfollowed byyesoryto delete that ZIP file. - Execute
ls. You should see a directory calledsurvey, which was inside of that ZIP file. - Execute
cd surveyto change into that directory. - Execute
ls. You should see this problem’s distribution inside.
Understanding
application.py
This file represents your web app’s “controller,” all of the logic that implements its functionality. Atop the file are a few imports of libraries followed by some configuration of Flask, per the comments therein. Below that are declarations of four routes, two of which are for you to do!
templates/layout.html
This file represents your web app’s layout, an HTML structure that all of your views will share.
templates/form.html
In this file will live your very own form, only the skeleton of which we’ve written for you.
templates/error.html
In this file is a template for any messages you might like to display to the user in the event of some error.
static/styles.css
In this file will be any of your own CSS properties for any or all of your app’s views.
Specification
- Complete the implementation of
templates/form.htmlin such a way that the form therein contains not only a button but also one or more- text fields of any type,
- checkboxes or radio buttons, or
- select menus. Style that form using Bootstrap so that it looks nicer than it would with raw HTML alone.
- Change the implementation of
post_form, a function inapplication.py, in such a way that it- no longer renders
error.html(which was just a placeholder so that you would see something when submitting your newly made form), - validates a form’s submission, alerting users with a
messageviaerror.htmlif they have not provided values for one or more fields, - writes the form’s values to a new row in
survey.csvusingcsv.writerorcsv.DictWriter, and - redirects the user to
/sheet.
- no longer renders
- Complete the implementation of
get_sheet, another function inapplication.py, in such a way that it- reads past submissions from
survey.csvusingcsv.readerorcsv.DictReaderand - displays those submissions in an HTML
tablevia a new template. Style that table using Bootstrap so that it looks nicer than it would with raw HTML alone.
- reads past submissions from
Provided you meet these specifications, you’re welcome to alter the aesthetics of your app however you’d like, as via Bootstrap or your own CSS and HTML.
References
Staff’s Solution
It is reasonable to view its HTML and CSS.
How to Submit
Click Share toward your IDE’s top-right corner, then share your IDE with all three of these GitHub usernames:
arturojrealdmalanelhumphrey