Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python flask ImmutableMultiDict

This is my code:

@user_bp.route('/band', methods=['GET', 'POST']) def band_details():     from include.form.User import Banddetails     form = Banddetails()      if request.method == 'POST' and  form.validate_on_submit():           pippo =  request.args.getlist('name[]')          print 'sei passato di qui' + str(len(pippo))          for item in pippo:              print item                return "result"             return render_template("banddetails.html", form=form, session=session) 

I have a similar form:

<input type="text" name="name[]" id="name" value=""> 

I want get the element name[], lastname[], ... but I don't understand the procedure described in the flask api.

like image 614
Matteo Avatar asked Apr 21 '14 20:04

Matteo


People also ask

What is request form flask?

In the client-server architecture, the request object contains all the data that is sent from the client to the server. As we have already discussed in the tutorial, we can retrieve the data at the server side using the HTTP methods.

What does request args get do?

request.args is a MultiDict with the parsed contents of the query string. From the documentation of get method: get(key, default=None, type=None) Return the default value if the requested data doesn't exist.


1 Answers

If you are using an HTTP POST method you need to retrieve parameters like this:

 pippo =  request.form.getlist('name[]') 

If you use HTTP GET method, do it like this:

 pippo =  request.args.getlist('name[]') 

Check the docs here.

like image 69
kartheek Avatar answered Oct 05 '22 21:10

kartheek