简体   繁体   English

我的Google App Engine网站仅在迁移到python 2.7后才显示我的主页

[英]My google app engine website is only displaying my main page after migrating to python 2.7

Can anyone give me some pointers on how to get the other pages to show? 谁能给我一些如何使其他页面显示的指示? I this is my main.py 我这是我的main.py

import webapp2
import os
import jinja2

jinja_environment = jinja2.Environment(autoescape=True,
  loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__))))

class MainPage(webapp2.RequestHandler):
    def get(self):
        template = jinja_environment.get_template('index.html')
        self.response.write(template.render())


application = webapp2.WSGIApplication([
                                        ('/',MainPage),
                                        ], debug=True)

And this is my app.yaml 这是我的app.yaml

application: ftmyersptcong
version: 1
runtime: python27
api_version: 1
threadsafe: true

libraries:
- name: jinja2
  version:  latest

handlers:  
- url: /styles
  static_dir:  styles

- url: /images
  static_dir:  images

- url: /scripts
  static_dir:  scripts

- url: /.*
  script: main.application

I keep getting a 404 Not Found Page when I to click on any of the links to other pages which have been href'd in my html code. 我单击html代码中指向href的其他页面的任何链接时,始终收到404 Not Found页面。 This is what is in the log: 这是日志中的内容:

INFO     2014-11-12 18:15:42,434 module.py:652] default: "GET / HTTP/1.1" 500 -
INFO     2014-11-12 18:28:21,151 module.py:652] default: "GET / HTTP/1.1" 200 1274
INFO     2014-11-12 18:28:21,272 module.py:652] default: "GET /styles/main.css HTTP/1.1" 200 1880
INFO     2014-11-12 18:28:27,512 module.py:652] default: "GET /downloads.html HTTP/1.1" 404 154

You have a handful of static directory routes defined in your app.yaml (images, scripts, styles) -- that's why your css file is loading fine, for example. 在app.yaml中定义了一些静态目录路由(图像,脚本,样式),例如,这就是CSS文件可以正常加载的原因。 Then you have everything not matching those directories going to "application" in your "main.py" file. 然后,所有与“ main.py”文件中转到“ application”的目录都不匹配的目录。

In there, you are currently only defining one route -- "/" and MainPage is defined as your handler for that route. 在这里,您当前仅定义一个路由-“ /”,MainPage被定义为该路由的处理程序。 Calls to "/downloads.html" get sent to that same router, but since it doesn't match the "/" route, a 404 is returned. 对“ /downloads.html”的调用将发送到同一路由器,但是由于它与“ /”路由不匹配,因此将返回404。

You need to define your other route(s) and handlers in your main.py. 您需要在main.py中定义其他路由和处理程序。 For example: 例如:

application = webapp2.WSGIApplication([
                                        ('/',MainPage),
                                        ('/downloads.html',DownloadPage)
                                        ], debug=True)

Then you'd define DownloadPage similarly to MainPage to handle that route. 然后,您将定义与MainPage类似的DownloadPage来处理该路由。 You can also do pattern matches in the route definition in order to pass along variable info, but for your example, the above should work. 您也可以在路由定义中进行模式匹配,以传递变量信息,但是对于您的示例,上述方法应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM