Sessions
Last updated
Last updated
Masonite comes with a simple way to store sessions. Masonite supports the following session drivers: and .
Session configuration is located at config/session.py
file. In this file, you can configure which driver to use.
Masonite is configured to use the Cookie session driver by default, named cookie
.
Cookie driver will store all session data in the users cookies. It can be used as is.
Redis driver is requiring the redis
python package, that you can install with:
Then you should define Redis as default driver and configure it with your Redis server parameters:
Finally ensure that the Redis server is running and you're ready to start using sessions.
To save session data you can simply "set" data into the session:
Flash data is data specific to the next request. This is useful for data such as error messages or alerts:
To get back the session data you set you can simply using the "get" method:
You can check if a session has a specific key:
You can also delete a key from the session
You can reset all data in a session: