webapp2 中的嵌套路由
Nested routing in webapp2
我正在尝试创建一个 URL 路由,如下所示:
/view/数据库/table
其中数据库和table参数化
映射到像
这样的处理程序
class ViewTable:
def get(self, database, table):
#get table schema
我想知道如何路由它?
我试过了,但没用:
application = webapp.WSGIApplication([('/view/(.*)/(.*)', ViewTable), ], debug=True)
问题是您用来设置路由的正则表达式(它们是贪婪的,所以 /
匹配 .*
。更好的设置方法是:
application = webapp.WSGIApplication([
(r'/view/<database:[^/]*>/<table:[^/]*>', ViewTable),
], debug=True)
不过,更好的方法是使用正则表达式来准确捕获您的数据库和 table 名称可以捕获的字符。
我正在尝试创建一个 URL 路由,如下所示:
/view/数据库/table
其中数据库和table参数化
映射到像
这样的处理程序class ViewTable:
def get(self, database, table):
#get table schema
我想知道如何路由它?
我试过了,但没用:
application = webapp.WSGIApplication([('/view/(.*)/(.*)', ViewTable), ], debug=True)
问题是您用来设置路由的正则表达式(它们是贪婪的,所以 /
匹配 .*
。更好的设置方法是:
application = webapp.WSGIApplication([
(r'/view/<database:[^/]*>/<table:[^/]*>', ViewTable),
], debug=True)
不过,更好的方法是使用正则表达式来准确捕获您的数据库和 table 名称可以捕获的字符。