![]() async def index_view( request): await load_session(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. ![]() Middleware(SessionMiddleware, store=session_store, cookie_https_only= False, lifetime= 3600 * 24 * 14), ![]() You can change these defaults by changing cookie_https_only and lifetime arguments: from starlette.middleware import Middlewareįrom starsessions import CookieStore, SessionMiddleware The cookie lifetime is limited to the browser session and sent via HTTPS protocol only. Middleware(SessionMiddleware, store=session_store, lifetime= 3600 * 24 * 14),īy default, the middleware uses strict defaults. Session_store = CookieStore(secret_key= 'TOP SECRET') Load session in your view/middleware by calling load_session(connection) utility.įrom starlette.applications import Starletteįrom starlette.middleware import Middlewareįrom starlette.responses import JSONResponseįrom starsessions import CookieStore, load_session, SessionMiddlewareĪsync def index_view( request): await load_session(request).Configure session store and pass it to the middleware,.Add starsessions.SessionMiddleware to your application to enable session support,.See example application in examples/ directory of this repository. Install starsessions using PIP or poetry: pip install starsessions Advanced sessions for Starlette and FastAPI frameworks
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |