I\'ve setup a static website on GAE using hints found elsewhere, but can\'t figure out how to return a 404 error. My app.yaml file looks like
- url: (.*)/
I have reviewed all the above given answers and used the following at the end as the most universal 404 solution:
Add this link at the end of app.yaml
- url: /(.*)
script: 404.app
and create 404.py
with the following content
import webapp2
from google.appengine.ext.webapp import template
class NotFound(webapp2.RequestHandler):
def get(self):
self.error(404)
self.response.out.write(template.render('404.html', {}))
app = webapp2.WSGIApplication([
('/.*', NotFound)
], debug=True)
This will display contents of 404.html
file with 404 error code.
The advantage of this solution is simplicity, correctness of bahaviour and flexibility, as it allows to use a static 404.html
file as error page content.
I also want to warn against some of the solutions suggested above.
Custom Error Responses
don not work with 404 error