WTForm “OR” conditional validator? (Either email or phone)
问题 class ContactForm(Form): name = StringField('Name', validators=[DataRequired(), Length(max=255)]) email = StringField('Email', validators=[Optional(), Email(), Length(max=255)]) phone = StringField('Phone number', validators=[Optional(), NumberRange(min=8, max=14)]) comment = TextAreaField(u'Comment', validators=[DataRequired()]) Is there anyway to specify a validator such that either email or phone is required? 回答1: You can create a validate method on the form and do some manual checking.