tut07_sessions.py (732B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\lib\cherrypy\tutorial\tut07_sessions.py 2 import cherrypy 3 4 class HitCounter: 5 _cp_config = {'tools.sessions.on': True} 6 7 def index(self): 8 count = cherrypy.session.get('count', 0) + 1 9 cherrypy.session['count'] = count 10 return "\n During your current session, you've viewed this\n page %s times! Your life is a patio of fun!\n " % count 11 12 index.exposed = True 13 14 15 import os.path 16 tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') 17 if __name__ == '__main__': 18 cherrypy.quickstart(HitCounter(), config=tutconf) 19 else: 20 cherrypy.tree.mount(HitCounter(), config=tutconf)