使用django-allauth注册后防止用户登录 [英] prevent user login after registration using django-allauth

查看:110
本文介绍了使用django-allauth注册后防止用户登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在django应用中使用django-allauth。默认情况下,当用户成功注册后,他们会自动登录。如何覆盖默认行为,并防止用户在成功注册后登录。用户注册后,必须将他/她重定向到登录页面。已禁用电子邮件验证。谢谢。

i'm using django-allauth for my django app. by default, when a user successfully sign's up, they are automatically logged in. how do you override the default behaviour and prevent the user from logging in after after successful signup. After the user signs up, he/she must be redirected to the login page. ive disabled email verification. Thank you.

# settings.py
LOGIN_REDIRECT_URL = 'welcome'
ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS = False
ACCOUNT_LOGOUT_REDIRECT_URL = 'thanks'

ACCOUNT_EMAIL_REQUIRED = False
ACCOUNT_EMAIL_VERIFICATION = 'none'


推荐答案

如果您不需要电子邮件验证,则可以跳过这样的登录:

If you don't need the email verification, you can skip the login like this:

先入您的 urls.py ,您必须使用您自己的视图网址覆盖默认SignupView的网址:

First in your urls.py, you must override the url to the default SignupView with a url to your own view:

url(r^'accounts/signup/$', views.CustomSignupView.as_view(), name="account_signup")

然后在您的 views.py 中,您将拥有一个自定义视图,该视图将返回首页的路径,而不是继续登录用户。

Then in your views.py, you have a custom view that will return a path to your frontpage instead of continuing to login the user.

class CustomSignupView(SignupView):

    def form_valid(self, form):
        self.user = form.save(self.request)
        return redirect('/frontpage')

这篇关于使用django-allauth注册后防止用户登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆