8 python pyramid deform colander
如何在Deform/Colander中定义可以访问所有节点值的自定义验证器.我需要访问两个字段中的值才能确定某个特定值是否有效?
显而易见的答案是:
def verify_email_validator(form, values):
if values['email_address'] != values['verify_email']:
raise Invalid(form, 'Email values do not match')
class MySchema(MappingSchema):
def __init__(self, *args, **kwargs):
super(KickEntrySchema, self).__init__(*args, **kwargs)
self.validator=verify_email_validator # entire form validator
email_address = SchemaNode(Email())
verify_email = SchemaNode(Email())
Run Code Online (Sandbox Code Playgroud)
请注意,仅当各个字段验证器均未引发错误时,才会调用表单验证器。