PERMANENT_SESSION_LIFETIME?By default, Flask sessions are not permanent, so they last only until the browser is closed. This means the session cookie is a browser session cookie.
PERMANENT_SESSION_LIFETIME is set to 1 day and session.permanent = True is set?from flask import Flask, session
from datetime import timedelta
app = Flask(__name__)
app.secret_key = 'secret'
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=1)
@app.route('/')
def index():
session.permanent = True
session['user'] = 'Alice'
return 'Session set'session.permanent = True changes the cookie type.When session.permanent is set to True, Flask uses the PERMANENT_SESSION_LIFETIME config to set the cookie expiration. Here it is 1 day.
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(minutes=5) and session.permanent = True in their Flask app. But the session still lasts longer than 5 minutes. What is the most likely reason?Flask refreshes the session expiration time only when the session cookie is updated. If the cookie is not refreshed on each request, the expiration time remains fixed from the first set.
The correct config key is PERMANENT_SESSION_LIFETIME. Other options are invalid or do not exist.
PERMANENT_SESSION_LIFETIME set to 10 minutes and session.permanent = True. A user makes a request at 12:00, then another at 12:08, and then at 12:15. Assuming the session cookie is updated on each request, at what time will the session expire if the user stops making requests after 12:15?Flask resets the expiration time on each request that updates the session cookie. So the expiration moves forward with each request.
