python第一个web程序

例一:

import web
urls= ('/(.*)','index')
 
app= web.application(urls,globals())
class index:   
    def GET(self, name):
        if not name:
            name = 'world'
        web.header('Content-Type','text/html; charset=UTF-8')
        return 'python web dgx'
 
if __name__ == "__main__":
    app.run()


运行之后,浏览器输入

http://127.0.0.1:8080/

例二:

import web
urls = ('/(.*)', 'hello')
app= web.application(urls,globals())
class hello:
    def GET(self, name):
        i = web.input(times=1)
        if not name: name = 'world'
        for c in xrange(int(i.times)):
            print 'Hello,', name+'!'
            return 'hello ,%s' % name
if __name__ == "__main__":    
    app.run()

 运行之后,浏览器输入

http://127.0.0.1:8080/任意字符串

 

参考文章:http://www.oschina.net/question/5189_4306

posted @ 2015-05-04 11:08  kin2321  阅读(238)  评论(0编辑  收藏  举报