I'm deeply confused about how CSV files work in this context. Below is my application.py code and my form.html code; I can't see how to use Jinja to call on the information stored in my CSV file. In my mind, I visualise the CSV as a literal list of values separated by commas, and so I have no idea how to go about taking those values (after storing them in surveyReader) and putting the information inside the correct place inside the table I set up in the html file.

I've been debugging for almost a week now, and I really have never wanted to quit more. Whenever I run my program, the form works but the sheet/table doesn't display--it gives me a 500 internal server error. Please help!

relevant application.py code:

@app.route("/form", methods=["POST"])
def post_form():
    name = request.form.get("name")
    if not name:
        render_template("error.html", message = "missing name!")
    gender = request.form.get("gender")
    if not gender:
        render_template("error.html", message = "missing gender!")
    tShirtSize = request.form.get("tShirtSize")
    if not tShirtSize:
        render_template("error.html", message = "missing t-shirt size!")
    feedback = request.form.get("feedback")
    # actually store on cs50 csv file
    with open('survey.csv', 'a', newline='') as csvfile:
        surveyWriter = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL)
    surveyWriter.writerow((name, gender, tShirtSize, feedback))
    return redirect("/sheet")

@app.route("/sheet", methods=["GET"])
def get_sheet():
    # open a reader that reads the values of the csv file into
    with open('survey.csv', newline='') as csvfile:
        surveyReader = csv.reader(csvfile, delimiter=' ', quotechar='|')
    return render_template("sheet.html", row = row)

sheet.html code:

{% extends "layout.html" %}

{% block main %}

<table class = "table table-dark">
        <th scope = "col">
        <th scope = "col">
        <th scope = "col">
            t-shirt size
        <th scope = "col">
        {% for row in surveyReader %}
                            {{ row[0] }}
                            {{ row[1] }}
                            {{ row[2] }}
                            {{ row[3] }}
        {% endfor %}

{% endblock %}
  • If there's a 500, you likely have an error message and stack trace on your terminal. That error message might point you to the mistake.
    – Blauelf
    Sep 2, 2019 at 13:43

1 Answer 1


i think what's wrong is that you supplied the render template statement with row while you should have supplied it with surveyreader , row is just an iterator and need not be supplied to render template so your statement be like this $return render_template("sheet.html",surveyreader=surveyreader)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .