Your browser does not support JavaScript!
Upvotes Anonymous 5 User 0

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()
Was this helpful?

Comments

Leave a Comment

I agree to the Terms of Service
Design © 2015, Downranked, LLC.,
Original user code contributions under MIT License