我正在尝试制作一个网站,人们只输入他们的电子邮件地址,并且他们使用 cookie 和所有内容登录。在稍后阶段,我会要求他们提供密码和姓名,但不会使用任何用户名。我正在尝试使用 django-registraition 来执行此操作,但是我遇到了错误并且遇到了一些问题。
首先禁用用户名作为登录功能,我把 str(time()) 而不是用户名 - 我一直在寻找每次都会改变的东西。
但是,当我跳过身份验证(我目前不需要)时,我收到错误:
'RegistrationProfile' object has no attribute 'backend'
或者,我可以留下身份验证,但我不知道如何仅使用电子邮件和没有密码进行身份验证。另外,我不知道如何使下一行工作:
auth.login(request, ProfileUser)
如果有人能让我离开这里,那就太棒了。这是一些代码:
我的表格类:
class RegistrationFormCustom(forms.Form):
email = forms.EmailField()
def do_save(self):
new_u = User(username=str(time()),email= self.cleaned_data.get('email'),)
new_u.save()
new_p = Profile.objects.create_profile(new_u)
new_p.save()
return new_p
我的观点:
def registerCustom(request, backend, success_url=None, form_class=None,
disallowed_url='registration_disallowed',
template_name='registration/registration_form.html',
extra_context=None,
initial={}):
form = RegistrationFormCustom(initial=initial)
if request.method == 'POST':
form = RegistrationFormCustom(initial=initial, data=request.POST)
if form.is_valid():
profile = form.do_save()
profile = auth.authenticate(username = profile.user.email, password = form.cleaned_data.get('pass1'))
print(profile)
auth.login(request, profile)
return redirect('/')
else:
pass
return render_jinja(request, 'registration/registration_form.html',
type="register",
form = form
)
我会愉快地发布任何其他需要的剪辑