Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine GAE中的简单静态网站,带有自定义404错误页面_Google App Engine_Static_Web_Http Status Code 404_Webapp2 - Fatal编程技术网

Google app engine GAE中的简单静态网站,带有自定义404错误页面

Google app engine GAE中的简单静态网站,带有自定义404错误页面,google-app-engine,static,web,http-status-code-404,webapp2,Google App Engine,Static,Web,Http Status Code 404,Webapp2,我将GAE用于一个简单的静态网站,其中只有html/htm页面、图片等。我还将使用Python 2.7 所以我使用了一个简单的app.yaml和main.py,这很有效。然而,当访问一个不存在的页面时,它会显示一个标准的404页面。我想将其更改为自定义错误页面,并在下面尝试了此操作,但无效 以下是我的app.yaml和main.py文件: application: xxxx version: 11 runtime: python27 api_version: 1 threadsafe: true

我将GAE用于一个简单的静态网站,其中只有html/htm页面、图片等。我还将使用Python 2.7

所以我使用了一个简单的app.yaml和main.py,这很有效。然而,当访问一个不存在的页面时,它会显示一个标准的404页面。我想将其更改为自定义错误页面,并在下面尝试了此操作,但无效

以下是我的app.yaml和main.py文件:

application: xxxx
version: 11
runtime: python27
api_version: 1
threadsafe: true

default_expiration: "7d"

inbound_services:
- warmup

handlers:
- url: /
  static_files: index.html
  upload: index.html

- url: /(.*)
  static_files: \1
  upload: (.*)

- url: /.*
  script: main.app
Main.py:

import webapp2

class BaseHandler(webapp2.RequestHandler):
  def handle_exception(self, exception, debug):
    # Set a custom message.
    self.response.write('An error occurred.')

    # If the exception is a HTTPException, use its error code.
    # Otherwise use a generic 500 error code.
    if isinstance(exception, webapp2.HTTPException):
      self.response.set_status(exception.code)
    else:
      self.response.set_status(500)

class MissingPage(BaseHandler):
  def get(self):
    self.response.set_status(404)
    self.response.write('Page has moved. Pls look at http://www.yyyyyy.yy to find the new location.')

class IndexHandler(webapp2.RequestHandler):
    def get(self):
        if self.request.url.endswith('/'):
            path = '%sindex.html'%self.request.url
        else:
            path = '%s/index.html'%self.request.url

        self.redirect(path)

    def post(self):
        self.get()

app = webapp2.WSGIApplication(
   [  (r'/', IndexHandler),
      (r'/.*', MissingPage)
      ],
   debug=True)
什么是不正确的??我找到了很多条目,但没有一条能够准确地解释如何使用Python 2.7为简单的网站做到这一点


让我知道,非常感谢,Michael看起来除了404页面之外,你的网站不需要任何动态部分。 有一个错误。\u处理程序可以直接使用


省略.yaml文件中的第二个处理程序,您将在main.app中看到处理程序的结果。第二个处理程序应该做什么-
静态\u文件
:\1?感谢RGil,这是一个很好的线索,我尝试取出第二个处理程序,并得到了404自定义错误页面。但现在它只有index.html页面,而没有其他(105)页面、图像、样式表等。我使用第二个处理程序来处理所有其他页面。所以,有没有一种方法,我仍然可以作为静态文件提供所有105个文件,并获得自定义错误页面。
application: xxxx
version: 11
runtime: python27
api_version: 1
threadsafe: true

default_expiration: "7d"

inbound_services:
- warmup

handlers:
- url: /
  static_files: index.html
  upload: index.html

- url: /(.*)
  static_files: \1
  upload: (.*)

error_handlers:
- file: default_error.html