Google App2引擎中的Webapp2路由无效

时间:2016-09-28 20:13:18

标签: python-2.7 google-app-engine webapp2

我正在运行以下代码作为我的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),它打印'This is the HomeHandler'。如果我尝试访问https://myapp.appspot.com/products,我就会

  

在此服务器上找不到请求的网址/产品

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

1 个答案:

答案 0 :(得分:3)

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

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