In Flask convert form POST object into a representation suitable for mongodb

后端 未结 6 1615
难免孤独
难免孤独 2020-12-03 02:09

I am using Flask and MongoDB. I am trying to convert the content of request.form into something suitable for saving via PyMongo. It seems like something that should come up

6条回答
  •  眼角桃花
    2020-12-03 03:02

    >>> from werkzeug.datastructures import ImmutableMultiDict
    >>> imd = ImmutableMultiDict([('default', u''), ('required', u'on'), ('name', u'short_text'), ('name', u'another'), ('submit', u'Submit')])
    >>> imd.to_dict(flat=False)
    >>> {'default': [''], 
    'name': ['short_text', 'another'],
    'required': ['on'],
    'submit': ['Submit']}
    

    .to_dict(flat=False) is the thing to keep in mind. See the relevant documentation

提交回复
热议问题