Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping URL Pattern to a Single RequestHandler in a WSGIApplication

Is it possible to map a URL pattern (regular expression or some other mapping) to a single RequestHandler? If so how can I accomplish this?

Ideally I'd like to do something like this:

application=WSGIApplication([('/*',MyRequestHandler),])

So that MyRequestHandler handles all requests made. Note that I'm working on a proof of concept app where by definition I won't know all URLs that will be coming to the domain. Also note that I'm doing this on Google App Engine if that matters.

like image 937
Mark Roddy Avatar asked Jan 28 '26 08:01

Mark Roddy


1 Answers

The pattern you describe will work fine. Also, any groups in the regular expression you specify will be passed as arguments to the handler methods (get, post, etc). For example:

class MyRequestHandler(webapp.RequestHandler):
  def get(self, date, id):
    # Do stuff. Note that date and id are both strings, even if the groups are numeric.

application = WSGIApplication([('/(\d{4}-\d{2}-\d{2})/(\d+)', MyRequestHandler)])

In the above example, the two groups (a date and an id) are broken out and passed as arguments to your handler functions.

like image 74
Nick Johnson Avatar answered Jan 30 '26 22:01

Nick Johnson