【发布时间】:2018-11-08 10:01:52
【问题描述】:
我尝试了几种方法,但似乎无法成功。
这是我的代码:
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 不能使其成为必填字段?
【问题讨论】:
-
你应该调用
super()来检查继承的验证,这将验证required=True。
标签: python django content-management-system