0
不能在這裏找到我要去的地方。有兩個問題,但我覺得像一個簡單的配置更改將解決這兩個問題。Django-allauth和自定義註冊表格
當顯示下面的代碼時,密碼字段不會顯示。 Crispy-Forms生成警告無法解析表單字段「密碼」
當我手動添加密碼字段,並且我提交表單時,沒有任何反應。 IE瀏覽器。我返回到填寫表格的註冊頁面。但save_user()或signin()函數永遠不會被調用。沒有SQL錯誤消息或任何表單錯誤消息。
下面是設置:
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'
兩個ACCOUNT_SIGNUP和ACCOUNT_ADAPTER指向正確的文件,因爲我能夠做出改變看,反映。
這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()
我創建了一個表格,就像這裏列出How to customize user profile when using django-allauth
而且,這裏是自定義用戶模型(這是我剛建的關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})
任何幫助或點在正確的方向將是美好的!
感謝先進!