我试图在allauth注册表单中添加一些额外的字段(first_name和last_name)。我认为最好的方法是创建一个allauth SignupForm子类并添加我自己的字段(django非常新,所以如果我发现这个错误请告诉我)
我添加了
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
我不知道我做错了什么。非常感谢您提供的任何帮助
答案 0 :(得分:0)
https://stackoverflow.com/a/12308807/3415357
你不需要继承allauth.account.forms.SignupForm,你应该继承form.Form指定字段并编写你的自定义注册功能(用户名,电子邮件,密码应保持完整)