python - How do you validate a submitted form with a schema with formencode? -
python - How do you validate a submitted form with a schema with formencode? -
python beginner. on pyramid 1.5.1. @ point, i'm trying app work functionally.
i'm hard coding forms , trying utilize formencode validation.
i'm trying define schema, instantiate validator, , validate submitted form. i've been @ quite while, , can't seem find illustration anywhere on web, including project website.
here's i've got. i'm quite sure i'm missing stupid , simple. appears there no validate function, can't find anywhere in documentation i'm supposed phone call create validation happen.
error:
attributeerror: 'simpleformvalidator' object has no attribute 'validate' code:
class registrationschema(formencode.schema): allow_extra_fields = true password = formencode.validators.plaintext(not_empty=true) email = formencode.validators.email(resolve_domain=false) password = formencode.validators.string(not_empty=true) @view_config(permission='view', route_name='register', renderer='templates/user_add.pt') def user_add(request): pprint (vars(request.post)) formvalidator = simpleformvalidator(registrationschema) if 'form.submitted' in request.post , formvalidator.validate(): session = dbsession() email = form.data['email'] user = user( password=form.data['password'], email=form.data['email'] ) session.add(user) headers = remember(request, email) redirect_url = request.route_url('main') homecoming httpfound(location=redirect_url, headers=headers) login_form = login_form_view(request) logged_in = authenticated_userid(request) homecoming { 'logged_in': logged_in, 'login_form': login_form, } post:
{'reason': 'not form request'} {'_items': [('_csrf', '208f4c5344cf87fbbe2f79afde7d879b4e3ab7f5'), ('email', 'jeremy@test.com'), ('password', 'test'), ('submit', 'log in')]}
correct syntax:
formvalidator = registrationschema() valid = formvalidator.to_python(request.post) python formencode
Comments
Post a Comment