我正在尝试让表单检查电子邮件字段是否与我的Django表单中的verify_email字段匹配,但无法正常工作。
我的forms.py文件:
class SignupForm(ModelForm):
class Meta:
model = FormSubmission
fields ='__all__'
widgets = {'botcatcher': forms.HiddenInput()}
def clean(self):
cleaned_data = super().clean()
email = self.cleaned_data.get('email')
vmail = self.cleaned_data.get('verify_email')
if email != vmail:
raise forms.ValidationError(_("Emails must
match"), code="invalid")
return cleaned_data
我的model.py文件:
class FormSubmission(models.Model):
first_name = models.CharField(max_length = 30)
last_name = models.CharField(max_length = 30)
email = models.EmailField(unique= False)
verify_email = models.EmailField(unique = False)
text = models.CharField(max_length=250)
botcatcher = models.CharField(max_length= 1, blank=True,
validators=[validators.MaxLengthValidator(0)])
def __str__(self):
return "%s %s"% (self.first_name, self.last_name)
这是我对def clean功能的缩进。