【发布时间】:2014-11-17 19:39:31
【问题描述】:
我创建了这些路线:
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 看起来怎么样?
-
那里,我刚刚添加了它。
-
是
guestbook.py文件中的Empresa和EmpresaPerfil这两个类吗?这是在 app.yaml 中定义的项目的入口点 -
是的,它们都在 guestbook.py 中。
-
哦,我完全错过了,app.yaml 中的
- url: /empresa规则优先于处理程序EmpresaPerfil,如果您在templates/empresa/文件夹下没有perfil,它将返回404