我经历了webapp2 Route to match all other paths
我试着
class SinkHandler(webapp2.RequestHandler):
def get(self, *args, **kwargs):
self.response.out.write('Sink')
application = webapp2.WSGIApplication([
(r'/<:.*>', SinkHandler)
], debug = True)
为了匹配
http://localhost:9080/dummy
http://localhost:9080/dummy/eummy
http://localhost:9080/dummy/eummy/fummy
但它只是产生404未找到。
我可以这样做。
class SinkHandler(webapp2.RequestHandler):
def get(self, *args, **kwargs):
self.response.out.write('Sink')
application = webapp2.WSGIApplication([
(r'/(\w*)$', SinkHandler),
(r'/(\w*)/(\w*)$', SinkHandler),
(r'/(\w*)/(\w*)/(\w*)$', SinkHandler)
], debug = True)
它可以匹配上述3种类型的网址。但是,如果我需要支持
http://localhost:9080/dummy/eummy/fummy/gummy
我需要在WSGIApplication
是否有更聪明的方法来匹配所有其他可能的路径?
答案 0 :(得分:1)
这应该有效:
application = webapp2.WSGIApplication([
(r'/.*', SinkHandler)
], debug = True)
要使用更一般的正则表达式,您需要使用Route
:
from webapp2 import Route
application = webapp2.WSGIApplication([
Route(r'/<:.*>', SinkHandler)
], debug = True)