Sledro Sledro - 22 days ago 11
Python Question

How to submit a flask form to a list?

I am new to Python. I have a flask form that I am submitting. When I submit the form I am trying to post the data to a list as follows:

submittedWords=[]
for v in request.form.items():
submittedWords.append(v)


This give mt he following:

[('w1', 'first'), ('w2', 'second'), ('w5', 'third'), ('w7', 'fourth'), ('w4', ''), ('w6', ''), ('w3', '')]


Where w1,w2,w3.... is the input name and first,second,third... is the data entered/submitted.

Is this tuples inside a list?

Is there a way to just output the 'data' section such as

['first','second','third','fourth','','','']


Thanks in advance!

Answer

That's what items does; it iterates through the dictionary in the form of (key, value) pairs.

If you just want the values, iterate through those:

for v in request.form.values():
Comments