I send a HTTP request from a client. Then on the server I try to validate a WTForm Form.
from webob.multidict import MultiDict
from wtforms import Form, TextField, PasswordField, validators
class LoginForm(Form):
email = TextField('Email', [validators.Required(), validators.Email()])
password = PasswordField('Password', [validators.Required()])
The following commands are executed inside a RequestHandler:
self.request.body
>>> '{"username":"[email protected]", "password":"pass"}'
json.loads(self.request.body)
>>> {"username":"[email protected]", "password":"pass"}
type(json.loads(self.request.body))
>>> type 'dict'
MultiDict(json.loads(self.request.body))
>>> MultiDict[(u'username', u'[email protected]'), (u'password':'******')])
LoginForm(MultiDict(json.loads(self.request.body))).data
>>> {'password': 'pass', 'email': u''}
From the last command I'm expecting to see {"username":"[email protected]", "password":"pass"}
which I can later validate. However, somehow the actual data is 'lost'. Any ideas?
Your login form has the fields named
email
andpassword
yet you are passing it the fieldsusername
andpassword
.Change one or the other to match, and you should be good to go.