web2py custom 404 page when I raise the 404 myself

2019-07-30 14:28发布

问题:

I have a function in my controller that take an HTTP GET request. On certain argument values of that request I want to raise a 404. I also want that 404 to get rerouted to a different html page that I can make instead of giving that generic

404 NOT FOUND

or whatever with a message. I made a routes.py which is in the root directory of my application and it contains

routes_onerror[('myapp/404', 'myapp/static/404.html')]

And I also have a 404.HTML in my static folder. Is what I am trying to do the intended use of routes?

回答1:

Missing an =, and the URL should be preceded by a /:

routes_onerror = [('myapp/404', '/myapp/static/404.html')]