Disable Browser 'Back' Button After Logout?
Solution 1:
Finally found the solution:
from django.views.decorators.cache import cache_control
@cache_control(no_cache=True, must_revalidate=True)
def func()
#some code
return
This will force the browser to make request to server.
Solution 2:
You may find you need to use @cache_control(no_cache=True, must_revalidate=True, no_store=True) in chrome to fully stop any back button viewing.
The key thing being no_store for chrome as I found here 1
Solution 3:
+1 for Digital Cake's answer! This solved the problem of backing up into cached pages after logout on FireFox as well. I tried:
@cache_control(no_cache=True, must_revalidate=True)
on my views with no luck. Per Digital Cake, tried:
@cache_control(no_cache=True, must_revalidate=True, no_store=True)
and now Firefox backs up to the login screen.
Solution 4:
I know it's an old question, but the accepted answer did not work for me. i faced the same problem (using django 1.8 & Chrome)
Finally, I found the solution from the docs (django 1.7 or later). This will work for sure.
Just see the code below
from django.contrib.auth.decorators import login_required
@login_required(login_url='/login/')
def myview(request):
return HttpResponse(render(request,'path_to_your_view.html'))
@login_required
decorator is used to handle the issue. You can check more in doc
Solution 5:
The reason that you can the admin page, after you logged out and hit back is, that you don't see the real page. Rather you see a copy of it that is in your browser cache.
Try this:
- go to any admin page
- click "Logout"
- hit the "Back" button in your browser
- press F5 or click "Refresh" in your browser.
Now you will be redirected to the login page of the admin backend.
Post a Comment for "Disable Browser 'Back' Button After Logout?"