This page discusses custom error handling in CherryPy. Here's an example for providing the user with a custom 404 page (based on the 402 example from that page):
from controllers.home import HomeController
import cherrypy
def error_page_404(status, message, traceback, version):
return "404 Error!"
def start_server():
server_config = {
'server.socket_host': '0.0.0.0',
'server.socket_port': 60000
}
cherrypy.tree.mount(HomeController(), '/Home', {})
cherrypy.config.update(server_config)
cherrypy.config.update({'error_page.404': error_page_404})
cherrypy.engine.start()
if __name__ == '__main__':
start_server()
Leave a comment