1
class UserField(forms.EmailField):
def clean(self, value):
super(UserField, self).clean(value)
try:
User.objects.get(username=value)
raise forms.ValidationError("There is an existing account associated with this email.")
except User.DoesNotExist:
return value
try除了方法很簡單。但是,我有一個很難搞清楚的瞭解django表單的問題
super(UserField, self).clean(value)