http://webpy.org/static/webpy.gif WebPy ~ 超轻量WSGI 应用框架

::-- ZoomQuiet [DateTime(2008-02-24T06:19:46Z)] TableOfContents

Include(CPUGnav)

web.py 0.3 的食谱格式文档.

1. Hello World!

命题

怎么使用web.py 写个hello world?

解决

   1 import web
   2 
   3 urls = ("/.*", "hello")
   4 app = web.application(urls, globals())
   5 
   6 class hello:
   7     def GET(self):
   8         return 'Hello, world!'
   9 
  10 if __name__ == "__main__":
  11     app.run()

2. 客户对话~Sessions

命题
  • 如果在web.py 中运用 客户对话?
  • 解决
  • web.session模块专门进行了支持,以下实例

  •    1 import web
       2 urls = (
       3     "/count", "count",
       4     "/reset", "reset"
       5 )
       6 app = web.application(urls, locals())
       7 session = web.session.Session(app, web.session.DiskStore('sessions'), initializer={'count': 0})
       8 
       9 class count:
      10     def GET(self):
      11         session.count += 1
      12         return str(session.count)
      13 
      14 class reset:
      15     def GET(self):
      16         session.kill()
      17         return ""
      18 
      19 if __name__ == "__main__":
      20     app.run()
    

    Requests:

    3. web.py 食谱

    4. 反馈

    PageComment2 [:/PageCommentData:PageCommentData]