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

Hyb*_*rid 5 python django redirect login django-allauth

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

设置.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
Run Code Online (Sandbox Code Playgroud)

Nik*_*iko -1

您可以使用自定义帐户适配器。假设您的“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
Run Code Online (Sandbox Code Playgroud)