0

On my html I have script that creates form in a modal, from table. I have there text as well as file, so data is "multipart/form-data"

var modalForm = $('<form role="form" name="modalForm" action="/admin/" method="POST" enctype="multipart/form-data"></form>');

In my flask, I'm getting POST back with:

from werkzeug.datastructures import CombinedMultiDict, ImmutableMultiDict
imd = ImmutableMultiDict(request.form)

and I receive :

ImmutableMultiDict([('username', u'John'), ('email', u'john@snow.com')])

Which is weird for me - why i receive it as a immutableMultiDict, why it's not processed? but ok. Now If I would do:

for i in imd.itervalues():
   print i

I would get:

John

john@snow.com

Awesome! BUT why if I ask for

imd['username']

or

imd.get('username')

I am getting with unicode string

u'John' sure, I could fix that with str(imd['username']) but I haven't seen anyone else doing so within examples on internet. What might be wrong ?

When I have tried

CombinedMultiDict((request.files, request.form))

I received:

CombinedMultiDict((ImmutableMultiDict([('avatar', )]), ImmutableMultiDict([('username', u'John'), ('email', u'John@snow.com')])))

tmdag
  • 531
  • 6
  • 17
  • thanks! now I understand what it stands for, but should I get that prefix as a value of dict key ? – tmdag Nov 22 '16 at 06:51
  • If you do `print u'John'` it will print correctly. You may find this article helpful: [Pragmatic Unicode](http://nedbatchelder.com/text/unipain.html), which was written by SO veteran Ned Batchelder. BTW, proper Unicode handling is a lot saner in Python 3. – PM 2Ring Nov 22 '16 at 06:59

0 Answers0