python flask ImmutableMultiDict

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23205577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:29:31  来源:igfitidea点击:

python flask ImmutableMultiDict

pythonformsflask

提问by Matteo

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.

我想获取元素name[], lastname[], ... 但我不明白烧瓶 api 中描述的过程。

采纳答案by kartheek

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

如果您使用的是 HTTP POST 方法,则需要检索如下参数:

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

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

如果您使用 HTTP GET 方法,请执行以下操作:

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

Check the docs here.

检查这里的文档。

回答by Matthew Russell