django-allauth Redirect to Custom Page on Error

788 views Asked by At

I have moved the django-allauth login/signup forms to a modal on a custom index page I created. Everything works if the login/signup forms are filled without error, except the issue now is that if the login fails, I am redirected to /accounts/login/, and if signup fails, I am redirected to /accounts/signup/. How can I override this behavior, so that I am always redirected back to 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

There are 1 answers

1
Nikos Vita Topiko On

You can use a custom account adapter. assuming that your 'ra_app:index' is your base 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