Some questions about flash drive sessions

Consider the following simple flash application:

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:

  • As soon as the "enter_string" endpoint was visited and the user assigned a line session["string"], where is the line stored? Is it in the server or user memory?
  • By default, the session expires when you exit the browser. Is there an easy way for some other event to cause the session to expire, such as closing a window, but not necessarily a browser?
  • By default, will the session be delayed or will it remain until the browser exits no matter how long it takes?
+4
source share
1 answer

Flask -. (, , ). :

  • cookie. , , cookie .

  • , cookie Javascript. ( cookie session). , .

  • cookie , 31 . PERMANENT_SESSION_LIFETIME.

, Flask , . , , ( Flask-Session Flask-KVSession), , .

+7

Source: https://habr.com/ru/post/1611507/


All Articles