繁体   English   中英

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

[英]django-allauth Redirect to Custom Page on Error

我已将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

您可以使用自定义帐户适配器。 假设你的'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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM