Webapp2 Route to match all other paths

I have the following code in the main application. I expect all paths other than the first two to be caught by the last route (/.*). But I get error 404. What am I missing?

  import webapp2
  from webapp2 import WSGIApplication, Route

  # ---- main handler
  class MainPage(webapp2.RequestHandler):
    def get(self):
      ret = jinja2render.DoRender(self)
      return ret

  routes = [
    Route (r'/rpc', handler = 'rpc.RPCHandler'),
    Route (r'/secured/somesecuredpage', handler = 'secured.securedPageHandler'),
    Route (r'/.*', handler = MainPage),
  ]

  app = WSGIApplication(routes, debug=True)

I can change the last route from "/". to "/ <:.>" to catch all the other paths, but also requires me to include the named parameter in the MainPage.get function. Is this the only way to do it, or am I missing something? Thanks.

+4
source share
1 answer

According to the URI template docs, this should do the trick:

Route (r'/<:.*>', handler=MainPage)

MainPage.get , :

def get(self, *args, **kwargs):
+8

All Articles