4 Storing session data in CherryPy applications is very easy: cherrypy
5 provides a dictionary called "session" that represents the session
6 data for the current user. If you use RAM based sessions, you can store
7 any kind of object into that dictionary; otherwise, you are limited to
8 objects that can be pickled.
16 _cp_config
= {'tools.sessions.on': True}
19 # Increase the silly hit counter
20 count
= cherrypy
.session
.get('count', 0) + 1
22 # Store the new value in the session dictionary
23 cherrypy
.session
['count'] = count
25 # And display a silly hit count message!
27 During your current session, you've viewed this
28 page %s times! Your life is a patio of fun!
34 tutconf
= os
.path
.join(os
.path
.dirname(__file__
), 'tutorial.conf')
36 if __name__
== '__main__':
37 # CherryPy always starts with app.root when trying to map request URIs
38 # to objects, so we need to mount a request handler root. A request
39 # to '/' will be mapped to HelloWorld().index().
40 cherrypy
.quickstart(HitCounter(), config
=tutconf
)
42 # This branch is for the test suite; you can ignore it.
43 cherrypy
.tree
.mount(HitCounter(), config
=tutconf
)