So I have created a Django-app with a login form and using login(request, user) in my view.py to login the user. This is the main page and has the location mypage.com. I also created another function in my view.py called log_out:
def log_out(request):
logout(request)
return redirect('/')
This function is used to log out a user using the url: mysite.com/logout as defined in my url.py:
url(r'^logout/', views.log_out, name='log_out'),
This is working to log out the user, however the user is being logged out as I'm typing in the logout-url into the address-field of my browser, and before hitting enter to go to that endpoint.
I would like it to not log out the user when typing in the url, and wait until I'm "entering" the site.
Can anyone help me with this one?
What i am doing is redirecting the user to my login page.So I should say you should try this.My application only logouts after I hit the enter button.
url:-
app_name = 'name'
url(r'^logout$', user.logout_user, name='logout_user'),
url(r'^$', user.login_user, name='login'),
views:-
def logout_user(request):
logout(request)
return redirect('name:login')
I ended up using a POST-method as suggested by @danihp.