django-allauth在出错时重定向到自定义页面

时间:2016-12-19 18:34:23

标签: python django redirect login django-allauth

我已将django-allauth登录/注册表单移动到我创建的自定义索引页面上的模式。如果登录/注册表单填写没有错误,一切正常,除了现在的问题是如果登录失败,我被重定向到/accounts/login/,如果注册失败,我被重定向到/accounts/signup/。如何覆盖此行为,以便始终将我重定向回ra_app:index

settings.py

LOGIN_URL = 'ra_app:index'
LOGIN_REDIRECT_URL = 'ra_app:index'
ACCOUNT_LOGIN_REDIRECT_URL = 'ra_app:index'
ACCOUNT_LOGOUT_REDIRECT_URL = 'ra_app:index'
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True  # Used in conjunction with ACCOUNT_AUTHENTICATION_METHOD to ensure ability to login
ACCOUNT_USERNAME_REQUIRED = False  # Used in conjuction with ACCOUNT_AUTHENTICATION_METHOD to ensure ability to login
ACCOUNT_LOGOUT_ON_GET = True  # Logout without confirmation

1 个答案:

答案 0 :(得分:0)

您可以使用自定义帐户适配器。 假设您的' ra_app:index'是你的基本网址

# project/users/adapter.py:
from django.conf import settings
from allauth.account.adapter import DefaultAccountAdapter

class MyAccountAdapter(DefaultAccountAdapter):

    def get_login_redirect_url(self, request):
        path = "/"
        return path