我想添加一些額外的字段給allauth註冊表單(first_name和last_name)。我想做到這一點的最好辦法是創建一個allauth SignupForm子類,並添加自己的字段(很新的Django所以請讓我知道如果我要對這個錯誤的)定製django allauth表單
我加
ACCOUNT_SIGNUP_FORM_CLASS = 'accounts.forms.UserCreateForm'
到我的基地設置文件
,這裏是我的accounts.forms.py ...
from django.contrib.auth import get_user_model
from allauth.account.forms import SignupForm
from django import forms
class UserCreateForm(SignupForm):
class Meta:
fields = ("first_name", "last_name", "email", "username", "password1", "password2")
model = get_user_model()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["first_name"].label = ''
self.fields["first_name"].widget.attrs["placeholder"] = "First Name"
self.fields["last_name"].label = ''
self.fields["last_name"].widget.attrs["placeholder"] = "Last Name"
self.fields["email"].label = ''
self.fields["email"].widget.attrs["placeholder"] = "Email"
self.fields["username"].label = ''
self.fields["username"].widget.attrs["placeholder"] = "Username"
self.fields["password1"].label = ''
self.fields["password1"].widget.attrs["placeholder"] = "Password"
self.fields["password2"].label = ''
self.fields["password2"].widget.attrs["placeholder"] = "Confirm Password"
由於某種原因,我不斷收到錯誤...
django.core.exceptions.ImproperlyConfigured: Error importing form class accounts.forms: "cannot import name 'SignupForm'"
不知道爲什麼。顯然有一個在allauth.account.forms.py中的SignupForm,看到這裏... https://github.com/pennersr/django-allauth/blob/master/allauth/account/forms.py
我不知道我在做什麼錯。任何幫助,您可以給我們非常感謝