Consider the following simple flask app:
from flask import Flask, request, session
application = Flask(__name__)
application.secret_key = "some_random_string"
@application.route("/enter_string")
def start_session():
session["string"] = request.args["string"]
@application.route("/get_string")
def continue_session():
if "string" not in session:
return "Give me a string first!"
return "You entered " + session["string"]
if __name__ == "__main__":
application.debug = True
application.run()
Here are my questions:
- Once the "enter_string" endpoint has been visited and the user has assigned a string to
session["string"]
, where is the string stored? Is it in the server's memory or the user's? - By default, the session expires when the browser exits. Is there a simple way to have some other event trigger the expiration of the session, such as closing the window but not necessarily the browser?
- By default, will the session ever time out or is it kept until the browser exits no matter how long that takes?