网络编程
位置:首页>> 网络编程>> Python编程>> python脚本框架webpy的url映射详解

python脚本框架webpy的url映射详解

作者:枫少文  发布时间:2021-10-27 18:55:05 

标签:python,web框架,url映射

URL完全匹配(具体的url)

/index

URL模糊匹配(你根本就不知道index后面是什么,它根本不会返回参数)

/index/\d

URL带组匹配(主要有个'()',它的作用主要是返回参数,你处理的类中一定要有个参数接受)

/baidu/(.*)

实例


import web
urls=('/index','AbsoluteUrl',
   '/index/\d','AmbiguousUrl',
   '/index/(.*)','GroupUrl')
#具体的url处理类
class AbsoluteUrl:
   def GET(self):
       web.header('Content-type','text/html;charset=utf-8')
       return u'URL完全匹配'
#模糊的url处理类
class AmbiguousUrl:
   def GET(self):
       web.header('Content-type','text/html;charset=utf-8')
       return u'URL模糊匹配'
#分组的url处理类
class GroupUrl:
   def GET(self,name):  #如果你这里是带组匹配,一定要添加参数,用来接收你返回的参数
       web.header('Content-type','text/html;charset=utf-8')
       return u'URL带组匹配--'+name
app=web.application(urls,globals())
if __name__ == '__main__':
   app.run()

问题

1. urls为何不能使用dict,难道和它的原理有关
2. globals() 的作用还有哪些
3. 为何http://0.0.0.0:8080/,为何我们运行的时候一定要localhost:8080,这样设计有什么好处?

来源:https://blog.csdn.net/guofeng93/article/details/54170844

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com