There are two options: always autoload or autoload for specific paths only. We provide SessionAutoloadMiddleware to reduce amount of boilerplate code by autoloading session for you. Sometimes it is annoying to call load_session too often. Session autoloadįor performance reasons session is not autoloaded by default. You can automatically load session by using SessionAutoloadMiddleware middleware. session = 'value' # raises SessionNotLoaded async def index_view ( request ): request. However, if you try to access uninitialized session, SessionNotLoaded exception will be raised. async def index_view ( request ): await load_session ( request ) request. Call load_session to load data from the store. The session data is not loaded by default. The example above will let session usage over insecure HTTP transport and the session lifetime will be set to 14 days. You can change these defaults by changing cookie_https_only and lifetime arguments: from starlette.middleware import Middleware from starsessions import CookieStore, SessionMiddleware session_store = CookieStore ( secret_key = 'TOP SECRET' ) middleware = The cookie lifetime is limited to the browser session and sent via HTTPS protocol only. session return JSONResponse ( session_data ) session_store = CookieStore ( secret_key = 'TOP SECRET' ) app = Starlette ( middleware =, routes = ) Cookie securityīy default, the middleware uses strict defaults.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |