如何使用WSGIApplication()路由特定路径?

时间:2010-12-21 20:26:23

标签: python google-app-engine web-applications httpwebrequest

目前我有foo.com/bar路由到请求处理程序Main。我还希望foo.com/bar/id路由到该请求处理程序(其中“id”是对象的id)。

这是我尝试的但它失败了:

application = webapp.WSGIApplication(
                                     [('/bar', MainHandler),
                                     (r'/bar/(.*)', MainHandler)],
                                     debug=True)

我得到的错误是:

TypeError: get() takes exactly 1 argument (2 given)

1 个答案:

答案 0 :(得分:2)

您需要更改MainHandler.get方法的签名,如下所示:

class MainHandler(webapp.RequestHandler):
    def get(self, bar_id=None):
        if bar_id is None:
            # Handle /bar requests
        else:
            # Handle /bar/whatever requests