zl程序教程

您现在的位置是:首页 >  后端

当前栏目

python第一个web程序

PythonWeb程序 第一个
2023-09-14 09:11:30 时间

例一:

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