google app engine - Simple static website in GAE with custom 404 error page -
i using gae simple static website html/htm pages, pictures etc. using python 2.7.
so use straight forward app.yaml , main.py , works. however, when accessing page not exist, shows standard 404 page. want change 1 custom error page, , tried below not work.
here app.yaml , main.py files:
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 custom message. self.response.write('an error occurred.') # if exception httpexception, use error code. # otherwise use 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 @ http://www.yyyyyy.yy find 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)
what not correct?? find lot of entries, none explains how simple website python 2.7,
let me know, many thanks, michael
it looks doesn't need have dynamic part of website except 404 page. there error_handlers can used directly.
https://developers.google.com/appengine/docs/python/config/appconfig#custom_error_responses
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
Comments
Post a Comment