[CentralOH] WebPy and Cookies

Greg Singer gacsinger at gmail.com
Tue Sep 9 02:40:31 CEST 2008


On Mon, Sep 8, 2008 at 8:27 PM, Mark Erbaugh <mark at microenh.com> wrote:
> This is probably due to my lack of understanding.  I'm using WebPy to
> create a Python based web application.

Perhaps it's overkill, but I recommend that you use flup to handle
your cookies. Just insert the following into your code.py:

from flup.middleware.session import DiskSessionStore,
SessionMiddleware, MemorySessionStore #Choose memorysession or
disksession as appropriate
def session_mw(app):
  sessionStore=DiskSessionStore(storeDir="/tmp/sessions/", timeout=50)
  return SessionMiddleware(sessionStore, app)

class index:
  def GET(self):
    session = web.ctx.environ['com.saddi.service.session'].session
    #other code deleted

if __name__=='__main__':
  render=web.template.render('templates/',cache=False)
  web.run(urls,globals(),session_mw)

Note the code in the index class. This is how you retrieve the
session, which is accessed just like a dictionary.

 - Greg


More information about the CentralOH mailing list