I have a web server that has all of the configurations set in the code, but I want to be able to handle all page 404 errors. How would I go about doing this in Python?
See also http://www.cherrypy.org/wiki/ErrorsAndExceptions#AnticipatedHTTPresponses if you want more traditional replacement of 4xx and 5xx output.
Make a default handler in the root.
class Root:
def index(self):
return "Hello!"
index.exposed = True
def default(self, attr='abc'):
return "Page not Found!"
default.exposed = True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With