您的位置:首页 > 编程语言 > Python开发

python第一个web程序

2015-05-04 11:08 330 查看
例一:

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: