我想添加一些额外的字段给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
我不知道我在做什么错。任何帮助,您可以给我们非常感谢