It is often useful to store information relevant to a user of the app for the duration of that usage session. For example the user may choose to want to save a option or be remembered as logged in. This information can either be stored client side or server side and Quart provides a system to store the information client side via Secure Cookie Sessions.
The cookies used by default are not set to be permanent (deleted when
the browser’s session ends) to have permanent cookies
session.permanent must be
True when the session is
modified. To set this as the default use this snippet,
@app.before_request def make_session_permanent(): session.permanent = True
Sessions can be used with WebSockets with an important caveat about cookies. A cookie can only be set on a HTTP response, and an accepted WebSocket connection cannot return a HTTP response. Therefore the default implementation, being based on cookies, will lose any modifications made during an accepted WebSocket connection.