我正在开发一个基于Django框架的网站。我选择django allauth作为后端,并定制了它提供的标准登录表单,如下所示:
我的应用程序/表单.py公司名称:
from allauth.account.forms import LoginForm, SignupForm
from django import forms
class MyLoginForm(LoginForm):
def __init__(self, *args,
**kwargs):
super(LoginForm, self).__init__(*args, **kwargs)
self.fields['remember'].label = 'Remember me'
self.fields['remember'].initial = True
# To use a placeholder text we'll have to use below
login_widget = forms.TextInput(attrs={'type':'email',
'placeholder':
('Enter your email'),
'autofocus':'autofocus'
})
self.fields['email'] = forms.CharField(label=("Email"),
widget=login_widget)
self.fields['email'].label = 'Email'
def clean_email(self):
email = self.cleaned_data.get('email')
base, provider = email.split('@')
domain, extent = provider.split('.')
if extent == "edu":
forms.ValidationError("Please use a valid \
personal email address")
return email
class MySignUpForm(SignupForm):
def __init__(self, *args, **kwargs):
super(SignupForm, self).__init__(*args, **kwargs)
下面是我处理表单渲染的视图: 另一个应用程序/视图.py公司名称:
^{pr2}$鉴于上述情况,我有以下问题:
当我点击submit,网站显示KeyError在/。这可能是什么原因?回溯显示在'LoginForm'类中(在allauth/accounts中/表单.py)有一个名为Login的字段导致冲突。
如何真正让用户登录并转到纵断面图。
问题在于
MyLoginForm
初始化。从那里删除所有与电子邮件相关的代码。在您的设置.py然后使用__init__
方法仅重写占位符。检查heredjango all auth中是否已支持电子邮件。在相关问题 更多 >
编程相关推荐