Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webapp2 Route to match all other paths

Tags:

routes

webapp2

I've the following code in my main app. I expect all paths other than the first two to be caught by the last route (/.*). But I get 404 error. 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 other paths, but that also requires me to include a named parameter to MainPage.get function. Is that the only way to do or am I missing something? Thanks.

like image 842
user1928896 Avatar asked Feb 15 '23 05:02

user1928896


1 Answers

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

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

You may need to define your MainPage.get method as follows to accept with the extra arguments:

def get(self, *args, **kwargs):
like image 60
erichiggins Avatar answered Mar 03 '23 01:03

erichiggins