Optional URL Parameter in Route GAE webapp2

戏子无情 提交于 2019-12-04 10:03:25

You can set up a regex to parse IDs out of the URL. Here's a really premitive example using webapp2:

app = webapp2.WSGIApplication([('/', MainPage),
                               ('/property/(.*)', PropertyHandler)],
                              debug=True)

And you setup your request handler to accept the additional parameter:

class PropertyHandler(webapp2.RequestHandler):
    def get(self, propertyId):

For a real-world implementation, you'd want to be a bit more specific on the regex and add validation to the handler incase you get garbage or no ID.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!