Django Allauth注册阻止登录 [英] Django Allauth Signup Prevent Login
问题描述
是否仍然可以阻止Allauth注册表单自动登录用户?
Is there anyway to prevent the Allauth Signup form from automatically logging in the User?
我在这里找到了类似的帖子,没有答案:
I found a similar post here with no answers:
谢谢.
推荐答案
您已登录,因为此行为已包含在allauth的注册视图中.表单有效时,视图将调用名为 complete_signup
的函数,该函数执行以下两项操作:
You get logged in because this behavior is baked into the signup view of the allauth. When the form is valid, the view calls the function called complete_signup
that does two things:
- 发出
user_signed_up
信号 - 登录用户
要解决此问题,我们需要离开第1步,然后将第2步替换为简单的重定向.
To solve this, we need to leave the step 1 and replace the step 2 with a simple redirect.
这是可以完成的方法:
- 从
allauth/account/views.py
扩展SignupView,并覆盖其form_valid
方法,如下所示:
- Extend the SignupView from
allauth/account/views.py
and override itsform_valid
method like this:
Class CustomSignupView(SignupView):def form_valid(自我,形式):#通过将用户分配给视图上的属性,我们允许子类#SignupView来访问新创建的用户实例self.user = form.save(self.request)尝试:signal.user_signed_up.send(sender = self.user .__ class__,request = self.request,user = self.user,** {})返回HttpResponseRedirect(self.get_success_url())除了InstantHttpResponse作为e:返回e.response
还没有测试代码,但是应该可以正常工作.
Haven't tested the code, but it should be working.
- 在urls.py中连接新视图,以替换旧的注册"视图url.
这篇关于Django Allauth注册阻止登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!