Skip to content
Advertisement

WTForms-JSON not working with FormFields

Nested forms (FormFields) doesn’t get populated with data when I use WTForms-JSON. I can’t spot my mistake, see example below.

JavaScript

I send the following JSON-request

JavaScript

but the print after form.from_json(request.json) reveals that the address object is never populated with data (also, the “appropriate” errors are returned from the route).

Print output: {'name': u'Alex', 'address': {'street': u'', 'number': None}}

I’m using WTForms 2.0.2, WTForms-JSON 0.2.8

Is this a bug or am I doing something wrong? Thankful for any help!

Advertisement

Answer

I was using the from_json()-function wrong, as it is a class-function that returns an instantiated form. See updated code for route below.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement