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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With