Python 2.7 GAE app.yaml获取404错误

时间:2012-11-25 21:11:34

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

以下是我的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):  

def get(self):

template = jinja_environment.get_template(' index.html')   

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

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

修复程序位于粗体文本中!

1 个答案:

答案 0 :(得分:5)

app中的index变量似乎没有index.html的处理程序。例如:

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

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

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

因为这表面上是任何键入index.htmlindex.的任何其他排列的人的处理程序,所以您可以使用类似的东西来捕获更多的案例(因为在内部,您可以使用/如果您需要):

app = webapp2.WSGIApplication([
    ('/', MainPage),
    ('/index\..*', MainPage)
])
相关问题