我试了好几种方法,但似乎都不管用。你知道吗
这是我的密码:
class Meta:
model = User
# set fields to be used in registration form
fields = ['username','email','password','password2']
username = forms.CharField(required=True)
email = forms.EmailField(required=True, max_length=100) <---
password= forms.PasswordInput()
password2=forms.PasswordInput()
# user email must be unique
def clean_email(self):
email = self.cleaned_data.get('email')
# check if account with email exists
if email and User.objects.filter(email=email).exists():
raise forms.ValidationError('Email address already exists')
return email
有人知道为什么required=True不能作为必填字段吗?你知道吗
@WillemVanOnsem
在对您的问题的评论中所说的,我将在这里进行扩展以使其更清楚:您应该调用super().clean_email()
,以确保该字段的所有默认验证都已运行。你知道吗相关问题 更多 >
编程相关推荐