mik*_*892 1 python google-app-engine yaml python-2.7
以下是我的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
Run Code Online (Sandbox Code Playgroud)
来自index.py的代码
class 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)],debug = True)
修复程序位于粗体文本中!
看起来您的app
变量index
没有处理程序index.html
.例如:
app = webapp2.WSGIApplication([('/', MainPage)])
Run Code Online (Sandbox Code Playgroud)
如果您的应用程序被路由到index
,它将查看定义的处理程序并尝试找到匹配项/index.html
.在这个例子中,如果你去/
,它将工作正常,因为定义了该处理程序; 但是,如果你去index.html
,GAE不知道要调用哪个类,因此它返回404.作为一个简单的测试,请尝试
app = webapp2.WSGIApplication([
('/', MainPage),
('/index\.html', MainPage)
])
Run Code Online (Sandbox Code Playgroud)
由于这表面上是任何人打字index.html
或任何其他排列的处理程序index.
,你可以使用这样的东西来捕获更广泛的案例(因为在内部,你可以/
根据需要进行路由):
app = webapp2.WSGIApplication([
('/', MainPage),
('/index\..*', MainPage)
])
Run Code Online (Sandbox Code Playgroud)