我有一个非常简单的表格:
from django import forms
class InitialSignupForm(forms.Form):
email = forms.EmailField()
password = forms.CharField(max_length=255, widget = forms.PasswordInput)
password_repeat = forms.CharField(max_length=255, widget = forms.PasswordInput)
def clean_message(self):
email = self.clean_data.get('email', '')
password = self.clean_data.get('password', '')
password_repeat = self.clean_data.get('password_repeat', '')
try:
User.objects.get(email_address = email)
raise forms.ValidationError("Email taken.")
except User.DoesNotExist:
pass
if password != password_repeat:
raise forms.ValidationError("The passwords don't match.")
这是如何完成自定义表单验证的吗?我需要评估email
该电子邮件地址当前不存在用户。我还需要评估password
并password_repeat
匹配。我该怎么做呢?