forms.py
email = forms.EmailField()
email2 = forms.EmailField()
检查给定电子邮件的最佳解决方案是什么?
我试试
def clean(self, *args, **kwargs):
email = self.cleaned_data['email']
email2 = self.cleaned_data['email2']
if email != email2:
raise forms.ValidationError("Emails do not match")
return email
或
def clean(self):
if (self.cleaned_data.get('email') !=
self.cleaned_data.get('email2')):
raise ValidationError("Email addresses do not match.")
return self.cleaned_data
答案 0 :(得分:0)
我认为这两种解决方案都很好,但我更喜欢第二种解决方案,它更清洁,没有必要的变量。
再见!