Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Cherrypy 404 Error Handling

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?

like image 708
williamtroup Avatar asked Jan 08 '10 08:01

williamtroup


2 Answers

See also http://www.cherrypy.org/wiki/ErrorsAndExceptions#AnticipatedHTTPresponses if you want more traditional replacement of 4xx and 5xx output.

like image 74
fumanchu Avatar answered Nov 05 '22 05:11

fumanchu


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
like image 28
aatifh Avatar answered Nov 05 '22 07:11

aatifh