the redirect from /login/
when user is authenticated is handled in this method:
class RedirectAuthenticatedUserMixin(object):
def dispatch(self, request, *args, **kwargs):
if request.user.is_authenticated and app_settings.AUTHENTICATED_LOGIN_REDIRECTS:
redirect_to = self.get_authenticated_redirect_url()
response = HttpResponseRedirect(redirect_to)
return _ajax_response(request, response)
else:
response = super(RedirectAuthenticatedUserMixin, self).dispatch(
request, *args, **kwargs
)
return response
def get_authenticated_redirect_url(self):
redirect_field_name = self.redirect_field_name
return get_login_redirect_url(
self.request,
url=self.get_success_url(),
redirect_field_name=redirect_field_name,
)
the AUTHENTICATED_LOGIN_REDIRECTS is set by default to True according to documentation
using breakpoints to debug, I have found out that request.user.is_authenticated and app_settings.AUTHENTICATED_LOGIN_REDIRECTS
is always returning false, changing the condition to request.user.is_authenticated and settings.AUTHENTICATED_LOGIN_REDIRECTS
the condition was corrected and it returns True
and the user was redirected from /login/
URL to the one set in settings: LOGIN_REDIRECT_URL = "/"
my question why the app_settings was not able to fetch the variables in settings? and How do I fix this problem?
It is clear that the Django settings variable is ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS
, not AUTHENTICATED_LOGIN_REDIRECTS
(Ref the doc)
So, you should set the value for ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS
in your settings.py