Google App Engine:webapp2路由不起作用

问题描述 投票:1回答:1

我创建了以下路线:

app = webapp2.WSGIApplication([
  ('/', MainPage),
  ('/empresa', Empresa),
  ('/empresa/perfil', EmpresaPerfil),
], debug=True)

使用这些处理程序:

class Empresa(webapp2.RequestHandler):
  def get(self):
    template_values = {}
    template = JINJA_ENVIRONMENT.get_template('templates/empresa/index.html')
    self.response.write(template.render(template_values))

class EmpresaPerfil(webapp2.RequestHandler):
  def get(self):
    template_values = {}
    template = JINJA_ENVIRONMENT.get_template('templates/empresa/perfil.html')
    self.response.write(template.render(template_values))

但是每次我调用“ empresa / perfil”时,它都会返回404。

我以为它试图到达一个名为“ perfil”的参数的方法,但是修改响应处理程序后,我仍然遇到相同的错误。

我想念什么吗?

编辑:包括app.yaml

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

handlers:
- url: /img
  static_dir: templates/img/
- url: /empresa
  static_dir: templates/empresa/
- url: /estudiante
  static_dir: templates/estudiante/
- url: /css
  static_dir: templates/lib/css/
- url: /js
  static_dir: templates/lib/js/
- url: /templates
  static_dir: templates/
- url: /.*
  script: guestbook.app

libraries:
- name: webapp2
  version: "2.5.2"
- name: jinja2                                                                  
  version: latest 
python routing webapp2
1个回答
1
投票

事实证明,app.yaml没有抓住那条路。 我修改了以下行以解决此问题:

- url: /empresa/.*
  static_dir: templates/empresa/

感谢Rafael Barros的帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.