Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

obtaining a list of values from a POST using Flask

Tags:

python

post

flask

Using Flask, I'm trying to create a simple list of values POSTed from a web page. The only POSTed data will be the values associated with 1 to as many as 60 checkboxes, all named "state". The following code only returns the first value in the list, but all values are required for further processing:

[email protected]('/doCheck', methods = ['POST']) 
def doCheck():    
    d = request.form['state'] 

I tried using the method .getList() like so:

    d = request.form.getList('state')
    return d

...but get this error: AttributeError: 'ImmutableMultiDict' object has no attribute 'getList'

So I tried this instead:

    d = getList(request.form)
    return d

...and got the error NameError: name 'getList' is not defined.

That seems to indicate I should include a method or class but which one?

like image 915
user46622 Avatar asked Dec 15 '22 23:12

user46622


1 Answers

The method is getlist, without a capital L:

states = request.form.getlist('state')
like image 80
Daniel Roseman Avatar answered Jan 01 '23 12:01

Daniel Roseman