我已将 django-allauth
登录/注册表单移动到我创建的自定义索引页面上的模式。如果登录/注册表单填写无误,一切正常,除了现在的问题是,如果登录失败,我将被重定向到 /accounts/login/
,如果注册失败,我将被重定向到/帐户/注册/
。我怎样才能覆盖此行为,以便我总是被重定向回 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' 是你的基本 url
# 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
关于python - django-allauth 在出错时重定向到自定义页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41228861/