N
N
Nikita Lubchich2014-10-30 16:48:52
JavaScript
Nikita Lubchich, 2014-10-30 16:48:52

How to make WTForms parse an AJAX list?

There is a form:

class AuthorForm(Form):
    name = TextField('name', validators=[DataRequired()])
    books = FieldList(TextField('book', validators=[DataRequired()]))


There is JSON sent via PUT:
{
"books": ["Трудно быть Богом","Пикник на обочине","Парень из преисподней"],
"id":7,
"name":"Аркадий Стругацкий"
}


WTForms treats it like a dictionary, where, apparently, books is not parsed: Actually, how to fix it? Add-on: issues
{'name': 'Аркадий Стругацкий', 'books': []}


print(request.data)
b'{"books":["\xd0\xa2\xd1\x80\xd1\x83\xd0\xb4\xd0\xbd\xd0\xbe \xd0\xb1\xd1\x8b\xd1\x82\xd1\x8c \xd0\x91\xd0\xbe\xd0\xb3\xd0\xbe\xd0\xbc","\xd0\x9f\xd0\xb8\xd0\xba\xd0\xbd\xd0\xb8\xd0\xba \xd0\xbd\xd0\xb0 \xd0\xbe\xd0\xb1\xd0\xbe\xd1\x87\xd0\xb8\xd0\xbd\xd0\xb5","\xd0\x9f\xd0\xb0\xd1\x80\xd0\xb5\xd0\xbd\xd1\x8c \xd0\xb8\xd0\xb7 \xd0\xbf\xd1\x80\xd0\xb5\xd0\xb8\xd1\x81\xd0\xbf\xd0\xbe\xd0\xb4\xd0\xbd\xd0\xb5\xd0\xb9"],"id":7,"name":"\xd0\x90\xd1\x80\xd0\xba\xd0\xb0\xd0\xb4\xd0\xb8\xd0\xb9 \xd0\xa1\xd1\x82\xd1\x80\xd1\x83\xd0\xb3\xd0\xb0\xd1\x86\xd0\xba\xd0\xb8\xd0\xb9"}'

Python 3 version

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Abiduev, 2014-11-06
@gunlinux


json.dumps ("\"foo\bar")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question