Dynamic form fields in flask.request.form

半腔热情 提交于 2019-12-03 03:05:18

request.form returns a MultiDict object. Basically, it means that for 1 key, you could have multiple values. If you want to test what your form POST looks like, just do a quick print statement as follows

f = request.form
for key in f.keys():
    for value in f.getlist(key):
        print key,":",value

If you read the documentation for MultiDict, it says

"A MultiDict is a dictionary subclass customized to deal with multiple values for the same key which is for example used by the parsing functions in the wrappers. This is necessary because some HTML form elements pass multiple values for the same key."

http://werkzeug.pocoo.org/docs/datastructures/#werkzeug.datastructures.MultiDict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!