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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With