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

web.py中urls示例

2016-12-02 20:04 369 查看
1、urls一般都说多路由,我认为这个其实就是改变http不通的请求从而得到不同服务端程序的响应,从而将业务细化

2、代码示例

#coding:utf-8
import web
#urls rule
urls=(
"/(demo2.*)","demo1",
"/(demo1.*)","demo2"
)
#application information
app=web.application(urls,globals())
class demo1:
def GET(self, arg1):
web.header('Content-Type','text/html;charset=UTF-8')
return '1111111,'+'11111111'+'!'
print "this is application demo1"

class demo2:
def GET(self, arg1):
web.header('Content-Type', 'text/html;charset=UTF-8')
return '22222222222,' + '222222222222' + '!'
print "this is application demo2"

if __name__ == "__main__":
app.run()


3、说明

通过运行127.0.0.1:8000/demo1则响应内容为demo2类中内容

通过运行127.0.0.1:8000/demo2则响应内容为demo1类中内容
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  web.py urls python-web