How to Create a Custom 404 Page with CherryPy

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()

Comments

Leave a comment

What color are brown eyes? (spam prevention)
Submit
Code under MIT License unless otherwise indicated.
© 2020, Downranked, LLC.