python---正则中的(?P<name>group)

it2022-05-05  163

application=tornado.web.Application([ (r"/index/(?P<num>\d*)/(?P<nid>\d*)",home.IndexHandler), ],**settings)

结合函数

class IndexHandler(tornado.web.RequestHandler): def get(self,nid='',num=''): print(nid,num) self.write('<h1>hello world</h1>') (?P<num>\d*)是将后面匹配的\d*数据,取一个组名,这个组名必须是唯一的,不重复的,没有特殊符号函数可以获得这个组名下的数据,一种就是按照上面路由中的形式传递和被解析另一种是正则匹配使用group(组名)可以获取到这个组名下的数据,同group(1),group(2)类似

转载于:https://www.cnblogs.com/ssyfj/p/8522904.html


最新回复(0)