Skip to content

Clear a session in Flask

There are two ways to clear a Flask session. The most straightforward way is this:

from flask import session
session.clear()

You can also iterate over the session keys:

from flask import session
for key in session.keys():
    session.pop(key)

(source)

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.