[英]Django-allauth and custom Signup form
Cant seem to find where I am going wrong here. 无法在这里找到我要去的地方。 There are two issues, but I feel like a simple config change will fix both.
有两个问题,但是我觉得简单的配置更改就可以解决这两个问题。
When displaying the below code the password field does not get displayed. 显示以下代码时,不会显示密码字段。 Crispy-Forms generates a warning Could not resolve form field 'password'
脆皮表格生成警告无法解析表格字段“密码”
When I add a password field manually, and I submit the form, nothing happens. 当我手动添加密码字段并提交表单时,没有任何反应。 Ie.
就是 I am returned to the signup page with the form filled out.
我将返回填写表单的注册页面。 But save_user() or the signin() function never gets called.
但是save_user()或signin()函数永远不会被调用。 There are no SQL error messages or any form error messages.
没有SQL错误消息或任何形式的错误消息。
Below are the settings: 以下是设置:
ACCOUNT_SIGNUP_FORM_CLASS = 'house.users.forms.SignupForm'
AUTH_USER_MODEL = 'users.User'
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'optional'
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_ADAPTER = 'house.users.adapters.AccountAdapter'
Both ACCOUNT_SIGNUP and ACCOUNT_ADAPTER point to the right files as I am able to make changes to see the, reflected. ACCOUNT_SIGNUP和ACCOUNT_ADAPTER都指向正确的文件,因为我可以进行更改以反映出来。
This forms.py 这个forms.py
class SignupForm(forms.Form):
first_name = forms.CharField(max_length=30)
last_name = forms.CharField(max_length=30)
def __init__(self, *args, **kwargs):
super(SignupForm, self).__init__( *args, **kwargs)
self.helper = FormHelper()
self.helper.form_show_labels = False
self.helper.field_class = ''
self.helper.layout = Layout(
Field('first_name', placeholder='First Name', autocomplete='off'),
Field('last_name', placeholder='Last Name', autocomplete='off'),
Field('email', placeholder='Email', autocomplete='off'),
Field('password', placeholder='Password', autocomplete='off'),
Div(Submit('Register', 'Register', css_class='btn btn-primary block full-width m-b'), css_class='form-group'),
HTML('<p class="text-muted text-center"><small>Already have an account?</small></p>'),
Div(HTML('<a class ="btn btn-sm btn-white btn-block" href="' + reverse('account_login') + ' " > Login </a>'),css_class='form-group' )
)
def signup(self, request, user):
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.save()
I have created a form just as outlined here How to customize user profile when using django-allauth 我已经创建了一个表单,这里概述了如何使用django-allauth时如何自定义用户配置文件
Also, here is the custom user model (which I just built off AllAuths version) 另外,这是自定义用户模型(我是基于AllAuths版本构建的)
class User(AbstractUser):
name = models.CharField(max_length=30, null=True)
birthdate = models.DateField(null=True, blank=True)
legal_name = models.CharField(max_length=50, blank=True, null=True)
is_agent = models.NullBooleanField(default=False, null=True)
short_bio = models.CharField(max_length=200, null=True, blank=True)
contacts = models.ManyToManyField(ContactDetails)
def __str__(self):
return self.first_name + ' ' + self.last_name
def get_absolute_url(self):
return reverse('users:detail', kwargs={'username': self.username})
Any help or points in the right direction would be wonderful! 任何帮助或指向正确方向的事情都太好了!
Thanks in advanced! 提前致谢!
After a few days off, I returned and found the silly mistake! 休息几天后,我回来了,发现了这个愚蠢的错误!
In my Form.py the password field is called 'password1' not password! 在我的Form.py中,密码字段称为“ password1”,而不是密码!
class SignupForm(forms.Form):
first_name = forms.CharField(max_length=30)
last_name = forms.CharField(max_length=30)
def __init__(self, *args, **kwargs):
super(SignupForm, self).__init__( *args, **kwargs)
self.helper = FormHelper()
self.helper.form_show_labels = False
self.helper.field_class = ''
self.helper.layout = Layout(
Field('first_name', placeholder='First Name', autocomplete='off'),
Field('last_name', placeholder='Last Name', autocomplete='off'),
Field('email', placeholder='Email', autocomplete='off'),
Field('password1', placeholder='Password', autocomplete='off'),
Div(Submit('Register', 'Register', css_class='btn btn-primary block full-width m-b'), css_class='form-group'),
HTML('<p class="text-muted text-center"><small>Already have an account?</small></p>'),
Div(HTML('<a class ="btn btn-sm btn-white btn-block" href="' + reverse('account_login') + ' " > Login </a>'),css_class='form-group' )
)
def signup(self, request, user):
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.save()
Great days! 美好的一天!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.