django中自定义注册表单中的重复输入错误

时间:2018-07-05 06:38:46

标签: django django-forms django-views django-authentication django-allauth

我们有一个django项目应用程序名称“ blog”。我们已经为具有以下字段的用户建立了自定义注册:名称,手机,电子邮件和密码。 在MYSQL DB中,它为表blog_Customuser给出“重复条目错误”,并且为电子邮件,密码在表中创建了条目,但没有为移动列创建条目。也没有在account_emailaddress表中进行任何输入。

在调试代码时,也不要在标记为调试的以下行代码处停止。

进入Settings.py-

ACCOUNT_SIGNUP_FORM_CLASS = 'blog.forms.AllauthUserRegisterForm' 

Form.py条目看起来像这样:

class AllauthUserRegisterForm(forms.ModelForm):
name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Name'}))
mobile = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Mobile'}))
#password = forms.CharField(widget = forms.PasswordInput)
class Meta:
    model = CustomUser
    fields = ['email', 'mobile']

Models.py条目如下所示:

class CustomUser(AbstractUser):
name = models.CharField(default='', max_length=200, blank=True)
mobile = models.PositiveIntegerField(null=True, blank=True)
email = models.EmailField(unique=True)
USERNAME_FIELD = 'email'
# to enforce that you require email field to be associated with
# every user at registration
REQUIRED_FIELDS = ["mobile"]
def __str__(self):
    return self.email

Table blog_customuser column details 
`id` int(11) NOT NULL AUTO_INCREMENT,
 `password` varchar(128) NOT NULL,
 `last_login` datetime(6) DEFAULT NULL,
 `is_superuser` tinyint(1) NOT NULL,
 `username` varchar(150) NOT NULL,
 `first_name` varchar(30) NOT NULL,
 `last_name` varchar(30) NOT NULL,
 `is_staff` tinyint(1) NOT NULL,
 `is_active` tinyint(1) NOT NULL,
 `date_joined` datetime(6) NOT NULL,
 `mobile` varchar(12) DEFAULT NULL,
 `name` varchar(200) NOT NULL,
 `email` varchar(254) NOT NULL,

0 个答案:

没有答案