Sessions
You need to edit your config file to use sessions. Here's an example:
[/] tools.sessions.on = True tools.sessions.storage_type = "file" tools.sessions.storage_path = "/home/site/sessions" tools.sessions.timeout = 60
This sets the session to be stored in files in the directory /home/site/sessions, and the session timeout to 60 minutes. The only thing required to have working sessions here is tools.sessions.on, other are optional. If you omit storage_type the sessions will be saved in RAM.
By default, the session ID is passed in a cookie, so the client's browser must have cookies enabled for your site.
To set data for the current session, use cherrypy.session['fieldname'] = 'fieldvalue', to get data use cherrypy.session.get('fieldname').
Locking sessions
By default, the 'locking' mode of sessions is 'implicit', which means the session is locked early and unlocked late. If you want to control when the session data is locked and unlocked, set tools.sessions.locking = 'explicit'. Then call cherrypy.session.acquire_lock() and cherrypy.session.release_lock(). Regardless of which mode you use, the session is guaranteed to be unlocked when the request is complete.
Expiring Sessions
You can force a session to expire with the cherrypy.lib.sessions.expire function. Simply call that function at the point you want the session to expire, and it will cause the session cookie to expire client-side.
Older versions
| replace this | with this | |
| 2.2 | tools.sessions | session_filter |
| 2.1 | session_filter | sessionFilter |
| storage_type | storageType | |
| storage_path | storagePath | |
| timeout | Timeout | |
| 2.0 | cpg.configOption.sessionStorageType, .sessionTimeout, .sessionCleanUpDelay, .sessionCookieName, .sessionStorageFileDir |

