prevent user login after registration using django-allauth

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 18:13:40

问题


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'

回答1:


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

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")

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')


来源:https://stackoverflow.com/questions/50568209/prevent-user-login-after-registration-using-django-allauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!