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: (.*)/ static_files: static\1/index.html upload: static/index.html - url: / static_dir: static
with all the static html/jpg files stored under the static directory. The above works for files that exist, but returns a null length file if they don’t. The answer is probably to write a python script to return a 404 error, but how do you set things up to serve the static files that exist but run the script for files that don’t?
Here is the log from fetching a non-existent file (nosuch.html) on the development application server:
ERROR 2008-11-25 20:08:34,084 dev_appserver.py] Error encountered reading file '/usr/home/ctuffli/www/tufflinet/static/nosuch.html': [Errno 2] No such file or directory: '/usr/home/ctuffli/www/tufflinet/static/nosuch.html' INFO 2008-11-25 20:08:34,088 dev_appserver.py] 'GET /nosuch.html HTTP/1.1' 404 -
You need to register a catch-all script handler. Append this at the end of your app.yaml:
In main.py you will need to put this code:
Replace
<Your 404 error html page>with something meaningful. Or better use a template, you can read how to do that here.Please let me know if you have problems setting this up.