Mapping a URL pattern to a single RequestHandler element in WSGIApplication

Is it possible to map a URL pattern (regular expression or another match) to one RequestHandler? If so, how can I do this?

Ideally, I would like to do something like this:

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

So, MyRequestHandler processes all executed requests. Please note that I am working on proving the concept of the application, where by definition I will not know all the URLs that will go to the domain. Also note that I do this in the Google App Engine, if that matters.

+3
source share
2 answers
application=WSGIApplication([(r'.*',MyRequestHandler),])

See AppEngine docs for more details.

+1
source

, , . , (get, post ..). :

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)])

( ) .

+8

Source: https://habr.com/ru/post/1710732/


All Articles