Filling WTForms FormField FieldList with data results in HTML in fields

后端 未结 2 1488
花落未央
花落未央 2020-12-04 17:18

I have a Flask app in which I can populate form data by uploading a CSV file which is then read. I want to populate a FieldList with the data read from the CSV. However, whe

2条回答
  •  佛祖请我去吃肉
    2020-12-04 17:47

    In response to the accepted answer: The append_entry function expects data, not a Form. So if you approach it like this your code also works as you'd expect. With the added benefit of being easier to maintain

    # First remap your list of tuples to a list of dicts
    students = [dict(zip(["student_id","student_name"], student)) for student in student_info]
    for student in students:
        # Tell the form to add a new entry with the data we supply
        classform.students.append_entry(student)
    

提交回复
热议问题