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

标签 python django redirect authentication django-allauth

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

相关文章:

php - .htaccess 如果文件存在则重定向

python - 从 Azure 服务总线读取的数据流

python - 将日期时间索引值转换为索引号

python - Windows 7中的django路径问题

python - 使用 form.py 编辑模型

python - 来自 manage.py 的数据库错误 : "TypeError: invalid postgreSQL type: bigint"

html - HTML 中的图片标签 src 是否遵循 302 重定向?

python - GAE 云数据存储 : Get most frequently written models

django - 你是如何设置你的 Django 开发环境的?

apache - .htaccess 使用 laravel 重定向到 ssl