Django电子邮件验证

晚上好,客户要求我为电子邮件创建第二个字段,例如虚拟字段,以便使用该字段来检查用户插入的电子邮件。这与我们使用password1和password2一样。那是现实的吗?

谢谢

评论
ret
ret

也许这些思路?

class SignupForm(ModelForm):
    email2 = forms.CharField(widget=forms.PasswordField)

    class Meta:
        model = User
        fields = '__all__'

    def clean_email2(self):
        email = self.cleaned_data.get("email")
        email2 = self.cleaned_data.get("email2")
        if email and email2 and email != email2:
            raise forms.ValidationError(
                self.error_messages['email_mismatch'],
                code='email_mismatch',
            )
        return email2
点赞
评论