Google App Engine Custom 404 Error Page
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more google app engine 404 handler about Stack Overflow the company Business Learn more about hiring developers or posting ads
Google App Engine 404 Not Found
with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow google app engine error: not found is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Google App Engine and 404 error up vote 35 down vote favorite
Google App Engine Custom Error Page
26 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 google app engine 404 page not found 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 - python google-app-engine http-status-code-404 share|improve this question edited Jun 29 '10 at 14:26 Aaron Harun 11.2k63557 asked Oct 10 '08 at 0:51 ctuffli 2,43722035 1 I would label this 'python' but I don't have access (yet)... –AJ. Nov 11 '09 at 19:03 add a comment| 9 Answers 9 active oldest votes up vote 33 down vote accepted You need to register a catch-all script handler. Append this at the end of your app.yaml: - url: /.* script: main.py In main.py you will need to put this code: from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app class NotFoundPageHandler(webapp.RequestHandler): def get(self): self.error(404) self.response.out.write('
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about
Gae 404 Error
hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges
Webapp2 404
Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each google app engine console other. Join them; it only takes a minute: Sign up Google App Engine custom 404 page for static files up vote 0 down vote favorite I'm working on a GAE application which largely consists of static content. I've configured http://stackoverflow.com/questions/189751/google-app-engine-and-404-error the following handlers: - url: /content/(.*\..*) static_files: static/content/\1 upload: static/content/(.*) - url: /content/(.+) static_files: static/content/\1.html upload: static/content/(.*)\.html The first handler is used to serve images, stylesheets, etc.; the second handles plain URLs like /content/zoo/monkeys/george and serves a corresponding HTML file. Right now, GAE is returning an empty page if there is no corresponding static file for a URL. I'd like to set up a custom 404 page for these cases, but apparently this is not straightforward. Answers to http://stackoverflow.com/questions/37082610/google-app-engine-custom-404-page-for-static-files similar questions suggested putting a "catch-all" handler on the bottom of my app.yaml, with a RequestHandler that generates the error page. However, /content/(.+) matches all URLs under /content/, valid or not, which means such a handler won't get invoked. I can only think of two other solutions: Route all requests through a dynamic handler, which writes out content for valid URLs, or an error page for invalid ones. I don't like this, because it is far less efficient than letting GAE serve the static files. Declare a separate static handler that explicitly matches each static file, and then put a "catch-all" handler at the bottom -- I don't like this either, because it would result in a long list of handlers. Is there another way to set up a proper 404 page for this case? python google-app-engine google-app-engine-python share|improve this question edited May 6 at 23:13 asked May 6 at 23:05 Tony the Pony 17.5k44136242 I think you have painted yourself into a corner. Appengine isn't designed with this use case in mind. –Tim Hoffman May 7 at 9:00 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote Try 'error_handlers'. error_handlers: - file: custom_404.html From GAE App.yaml documentation - Each file entry indicates a static file that should be served in place of the generic error response. If you specify a file element w
page handlers in the app.yaml file? 78 people starred this issue and may be notified of changes. Back to list Status: Fixed Owner: ---- Closed: Oct 2010 Type-Feature Priority-Medium log-1983105 Sign in to add a comment https://code.google.com/p/googleappengine/issues/detail?id=67 Reported by seanost...@gmail.com, Apr 8, 2008 In hopes of failing gracefully in the eyes of the user, can we assign custom pages or handler scripts for the common HTTP errors (404, 500, etc)? handlers: - error: 404 script: not_found.py - error: 500 script: sever_error.py Thanks, Sean Apr 10, 2008 Project Member #1 ma...@google.com (No comment was entered for this change.) Labels: -Type-Defect Type-Feature May 2, 2008 #2 yaakovs...@gmail.com Is there a work-around for google app this? Are http error like 500 thrown as an exception? Jun 5, 2008 #3 isk...@gmail.com I support this idea, but not Sean's formulation of it. HTTP error messages in general can't be controlled from app.yaml; many 404s, for example, are going to be generated inside script handlers anyway. Getting a suitable error page from there is a matter of configuring your Web framework correctly, not the app.yaml file. (And serving a custom 500 error page google app engine is asking a bit much, IMO, let alone via a script!) Custom error handlers in app.yaml, however, make total sense in conjunction with static handlers. Currently, GAE (or at least the dev server) returns a body-less 404 if a static handler cannot find the requested file, and this is very bad---it can cause some user agents to act oddly (Konqueror 3.5 certainly does). A non-empty 404 would be better, but of course a custom 404 would be best. Jun 13, 2008 #4 michaelronbernstein Note related issue 443 . Jul 16, 2008 #5 prosar...@gmail.com Please implement this, I mean, I can have a script handle all requests, but a static dir will not be able to map to the 404 pages, say, http://sarqa.appspot.com/unmappedurl goes to a specified 404 handler but, http://sarqa.appspot.com/static/missinghtml.html will not because /static is already mapped to static dir. This causes un-uniform display of 404 in the same app. Sep 26, 2008 Project Member #6 ma...@google.com (No comment was entered for this change.) Status: Acknowledged Dec 27, 2008 #7 chrisspen@gmail.com I'm not sure if this counts as a work-around, but the app-engine-patch project's port of Django (https://code.google.com/p/app-engine-patch/) supports a custom 404 page. Jan 16, 2009 #8 alexkon It would also be very nice to have custom over-quota error pages. Feb 25, 2010 #9 ster...@gmail.com Some way to gracefully handle platform-