I would like to allow the user to logout and redirect him directly to the login page. In Django User Authenication Page(https://docs.djangoproject.com/en/dev/topics/auth/),
logout_then_login(request[, login_url])
Logs a user out, then redirects to the login page.
URL name: No default URL provided
Optional arguments:
login_url: The URL of the login page to redirect to. Defaults to settings.LOGIN_URL if not supplied.
The problem i face is then i click the page, it reloads the page instead of going to the login page.
My code is below:
@login_required
def main(request):
"""
main view
"""
path = reverse('home', kwargs={'userpk': request.user.pk})
return HttpResponseRedirect(path)
@login_required
def home(request, userpk):
"""
home page view
"""
if int(userpk) != request.user.pk:
return HttpResponseForbidden()
return render(request,
'lex/main.html',
dictionary={'user': request.user,
'userpk': userpk})
def logoutnlogin(request):
"""
Logout n login back
"""
return logout_then_login(request,login_url=main(request))
I think i am doing some mistake not sure where.. Need some guidance…
You have to provide url of login page, so the line should be
Assuming
/loginis your login url, or you can usereversewith name of your login url inurls.py