1 回答
TA贡献1825条经验 获得超6个赞
基本上你缺少 ModelForm Meta
试试这个
class SignupForm(UserCreationForm):
def __init__(self, *args, **kwargs):
super(UserCreationForm, self).__init__(*args, **kwargs)
email = forms.CharField(
widget=forms.EmailInput(
attrs={
'class': 'input',
'placeholder': 'bearclaw@example.com'
}
))
...
# other fields (username and password)
...
def clean(self):
User = get_user_model()
email = self.cleaned_data.get('email')
if User.objects.filter(email=email).exists():
raise ValidationError("An account with this email exists.")
return self.cleaned_data
class Meta:
model = get_user_model()
fields = ('username', 'email')
添加回答
举报