1

下面是我的app.yaml文件的代码。如果我去localhost:8080/我的index.app负载正确。如果我去localhost:8080/index.html我得到一个 404 错误。如果我转到任何其他页面,例如localhost:8080/xxxx正确not_found.app加载。为什么我收到此/index\.html案例的 404 错误?

谢谢!

application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /index\.html
  script: index.app

- url: /
  script: index.app

- url: /assets
  static_dir: assets

- url: /*
  script: not_found.app

libraries:
- name: jinja2
  version: latest

来自 index.py 的代码

类 MainPage(webapp2.RequestHandler):

定义获取(自我):

模板 = jinja_environment.get_template('index.html')

self.response.out.write(template.render(template_values))

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

修复位于粗体文本中!

4

1 回答 1

5

看起来您的app变量 inindex没有index.html. 例如:

app = webapp2.WSGIApplication([('/', MainPage)])

如果您的应用程序被路由到index,它将查看定义的处理程序并尝试找到与/index.html. 在这个例子中,如果你去/,它会正常工作,因为该处理程序已定义;但是如果你去index.html,GAE 不知道调用哪个类,因此它返回一个 404。作为一个简单的测试,试试

app = webapp2.WSGIApplication([
    ('/', MainPage),
    ('/index\.html', MainPage)
])

由于这表面上是任何输入index.html或任何其他排列的处理程序index.,因此您可以使用类似的东西来捕获更广泛的案例(因为在内部,您可以在/需要时使用路由):

app = webapp2.WSGIApplication([
    ('/', MainPage),
    ('/index\..*', MainPage)
])
于 2012-11-25T21:25:38.730 回答