I
I
Ivan0_02021-10-18 22:27:34
Flask
Ivan0_0, 2021-10-18 22:27:34

Session is not deleted after the browser is closed. What could be the problem?

Good evening, I don’t understand why the session is not deleted after the browser is closed. Tell me what could be the problem ?

from flask import Flask, session
import datetime

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret'
app.permanent_session_lifetime = datetime.timedelta(days=10)


@app.route('/')
def index():
    if 'visits' in session:
        session['visits'] = session.get('visits') + 1
    else:
        session['visits'] = 1
    return f"viewing: {session['visits']}"

data = [1,2,3,4]
@app.route('/session')
def session_data():
    session.permanent = False
    if 'data' not in session:
        session['data'] = data
    else:
        session['data'][1] += 1
        session.modified = True

    return f"session_data: {session['data']}"

if __name__ == '__main__':
    app.run(debug=True)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question