Posted By

manatlan on 01/14/10


Tagged

python web


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

saman


python web with bottle and session (beaker)


 / Published in: Python
 

  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import bottle as web
  4. from beaker.middleware import SessionMiddleware
  5.  
  6. @web.route('/')
  7. def index():
  8. session=web.request.environ["beaker.session"]
  9. if "cpt" in session:
  10. session["cpt"]+=1
  11. else:
  12. session["cpt"]=1
  13. return "cpt:"+str(session["cpt"])
  14.  
  15. if __name__=="__main__":
  16.  
  17. session_opts = {
  18. "session.type": "file",
  19. 'session.cookie_expires': True,
  20. 'session.auto': True,
  21. 'session.data_dir': "cache",
  22. }
  23.  
  24. app = web.default_app()
  25.  
  26. app = SessionMiddleware(app, session_opts)
  27.  
  28. web.run(app=app,reloader=True)

Report this snippet  

You need to login to post a comment.