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

发布于 2024-10-08 20:00:01 字数 445 浏览 0 评论 0原文

目前我有 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)

Currently I have foo.com/bar routing to a request handler Main. I also want foo.com/bar/id to route to that request handler (where "id" is an id of an object).

Here's what I tried but it's failing:

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

The error I get is:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

注定孤独终老 2024-10-15 20:00:01

您需要更改 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

You need to change the signature of your MainHandler.get method, like so:

class MainHandler(webapp.RequestHandler):
    def get(self, bar_id=None):
        if bar_id is None:
            # Handle /bar requests
        else:
            # Handle /bar/whatever requests
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文