web.py與flask的demo

  1. web.py
import web
    urls = (
        '/', 'Hello',
        '/happy', 'Happy',
    )

    class Hello:
        def GET(self):
            return "Hello, world!"

    class Happy:
        def GET(self):
            return "Happy End!"

    if __name__ == "__main__":
        app = web.application(urls, globals())
        app.run()
  1. flask
from flask import Flask

    app = Flask(__name__)

    @app.route('/')
    def Hello():
        return "Hello, World!"

    @app.route('/happy')
    def Happy():
        return "Happy End"

    if __name__ == '__main__':
        app.run(debug=True)

3.tornadopython

import tornado.ioloop
    import tornado.web

    class Hello(tornado.web.RequestHandler):
        def get(self):
            self.write("Hello, world")

    class Happy(tornado.web.RequestHandler):
        def get(self):
            self.write("Happy End")

    urls = [(r"/", Hello),(r"/happy", Happy)]

    app = tornado.web.Application(urls)

    if __name__ == "__main__":
        app.listen(8888)
        tornado.ioloop.IOLoop.instance().start()
相關文章
相關標籤/搜索