Google 应用引擎中的 Webapp2 路由不工作

Webapp2 Routes in Google app engine not working

我运行下面的代码作为我的GAE应用。

class HomeHandler(webapp2.RequestHandler):
    def get(self):
        self.response.write('This is the HomeHandler.')

class ProductListHandler(webapp2.RequestHandler):
    def get(self):
        self.response.write('This is the ProductListHandler.')

class ProductHandler(webapp2.RequestHandler):
    def get(self, product_id):
        self.response.write('This is the ProductHandler. '
            'The product id is %s' % product_id)

app = webapp2.WSGIApplication([
    (r'/', HomeHandler),
    (r'/products', ProductListHandler),
    (r'/products/(\d+)', ProductHandler),
])

当我尝试访问时,只有“/”路由有效(https://myapp.appspot.com) which prints 'This is the HomeHandler'. If I try to access https://myapp.appspot.com/products,我得到

The requested URL /products was not found on this server

我是服务器端开发的新手。我做错了什么?

很可能您的 app.yaml 配置有误。确保你的 url 部分有 .*

handlers:
- url: .*
  script: main.app