I'm using django-alluth
for social login. My concern is how do I login to a specific url instead of the fixed LOGIN_REDIRECT_URL
in the settings.py
file?
When I try removing the LOGIN_REDIRECT_URL
and setting my login page url as accounts/login/?next=/some-url/
it doesn't work. It redirects to accounts/profile
which is a 404 in my code.
You need to override get_login_redirect_url
in DefaultAccountAdapter
.
# project/settings.py:
ACCOUNT_ADAPTER = 'project.users.adapter.MyAccountAdapter'
# 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 = "/accounts/{username}/"
return path.format(username=request.user.username)
docs
LOGIN_REDIRECT_URL = '/afterlogin'
ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS = True
This works for me...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With