簡體   English   中英

Google App Engine:webapp2路由不起作用

[英]Google App Engine: webapp2 routing not working

我創建了以下路線:

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 

事實證明,app.yaml沒有抓住那條路。 我修改了以下行以解決此問題:

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

感謝Rafael Barros的幫助:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM