django allauth:自定义注册不';救不了
我正在尝试创建一个自定义注册,填充与django allauth:自定义注册不';救不了,django,django-forms,registration,django-allauth,Django,Django Forms,Registration,Django Allauth,我正在尝试创建一个自定义注册,填充与用户有OneToOne关系的配置文件模型的字段。我的表单显示正确,但保存只会刷新页面。不过,使用django allauth附带的标准表单还是可行的 在我的forms.py中,我有一个自定义表单,它使用原始创建者发布的def signup(self)。这个函数似乎永远也不会被调用 设置.py # allauth settings SITE_ID = 1 ACCOUNT_LOGIN_ATTEMPTS_LIMIT = 5 ACCOUNT_USER_MODEL_U
用户
有OneToOne
关系的配置文件
模型的字段。我的表单显示正确,但保存只会刷新页面。不过,使用django allauth附带的标准表单还是可行的
在我的forms.py
中,我有一个自定义表单,它使用原始创建者发布的def signup(self)
。这个函数似乎永远也不会被调用
设置.py
# allauth settings
SITE_ID = 1
ACCOUNT_LOGIN_ATTEMPTS_LIMIT = 5
ACCOUNT_USER_MODEL_USERNAME_FIELD = 'username'
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_FORMS = {'signup': 'accounts.forms.SignupForm'}
class SignupForm(forms.ModelForm):
email = forms.EmailField(widget=forms.TextInput(
attrs={'type': 'email',
'placeholder': _('E-mail address')}))
password1 = PasswordField(label=_("Password"))
password2 = PasswordField(label=_("Password (again)"))
class Meta:
model = Profile
fields = '__all__'
def signup(self, request, user):
print "hi"
print request.POST
print user
new_profile = Profile()
new_profile.user = user
new_profile['field1'] = self.cleaned_data['field1']
new_profile['field2'] = self.cleaned_data['field2']
class Profile(models.Model):
user = models.OneToOneField(User)
field1 = models.CharField(max_length=255)
field2 = models.CharField(max_length=255)
forms.py
# allauth settings
SITE_ID = 1
ACCOUNT_LOGIN_ATTEMPTS_LIMIT = 5
ACCOUNT_USER_MODEL_USERNAME_FIELD = 'username'
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_FORMS = {'signup': 'accounts.forms.SignupForm'}
class SignupForm(forms.ModelForm):
email = forms.EmailField(widget=forms.TextInput(
attrs={'type': 'email',
'placeholder': _('E-mail address')}))
password1 = PasswordField(label=_("Password"))
password2 = PasswordField(label=_("Password (again)"))
class Meta:
model = Profile
fields = '__all__'
def signup(self, request, user):
print "hi"
print request.POST
print user
new_profile = Profile()
new_profile.user = user
new_profile['field1'] = self.cleaned_data['field1']
new_profile['field2'] = self.cleaned_data['field2']
class Profile(models.Model):
user = models.OneToOneField(User)
field1 = models.CharField(max_length=255)
field2 = models.CharField(max_length=255)
型号.py
# allauth settings
SITE_ID = 1
ACCOUNT_LOGIN_ATTEMPTS_LIMIT = 5
ACCOUNT_USER_MODEL_USERNAME_FIELD = 'username'
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_FORMS = {'signup': 'accounts.forms.SignupForm'}
class SignupForm(forms.ModelForm):
email = forms.EmailField(widget=forms.TextInput(
attrs={'type': 'email',
'placeholder': _('E-mail address')}))
password1 = PasswordField(label=_("Password"))
password2 = PasswordField(label=_("Password (again)"))
class Meta:
model = Profile
fields = '__all__'
def signup(self, request, user):
print "hi"
print request.POST
print user
new_profile = Profile()
new_profile.user = user
new_profile['field1'] = self.cleaned_data['field1']
new_profile['field2'] = self.cleaned_data['field2']
class Profile(models.Model):
user = models.OneToOneField(User)
field1 = models.CharField(max_length=255)
field2 = models.CharField(max_length=255)
最后需要调用save()
def signup(self, request, user):
.....
new_profile.save()