Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask- Back Button Returns to Session Even after Logout

Tags:

flask

I am creating a website using flask that requires logging in and out. I am using Flask-Security to help with this. My problem is that after I log out, if I hit the back button, I return to the user's page. Is there a way to prevent returning to a session after logging out by pressing the back button in Flask?

like image 405
user3016362 Avatar asked Dec 02 '22 21:12

user3016362


1 Answers

You can tell the browser not to cache any pages by adding the Cache-Control header after every response. If you only want this for some responses, you could add this to specific views instead.

# Ensure responses aren't cached
@app.after_request
def after_request(response):
    response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
    return response
like image 173
Wael Azar Avatar answered Dec 21 '22 10:12

Wael Azar