कुछ googling के आधार पर मैंने निम्न त्रुटि हैंडलर स्थापित किया। हालांकि पाइथन अपवाद जो http 500 लौटने के लिए प्रतीत होते हैं, वे इस सामान से फंसे नहीं हैं, हालांकि 404 हैं। प्रिंट स्टेटमेंट्स के साथ मैंने नीचे दिए गए कोड में छोड़ा है, मैं देख सकता हूं कि यह इनमें से किसी भी दिनचर्या को नहीं मारता है। मुझे वास्तव में क्या करना चाहिए? सब सेटोरनाडो एप्लिकेशन में आवेदन अपवादों को गहन रूप से संभालना
class ErrorHandler(tornado.web.RequestHandler):
"""Generates an error response with status_code for all requests."""
def __init__ (self, application, request, status_code):
print 'In ErrorHandler init'
tornado.web.RequestHandler.__init__(self, application, request)
self.set_status(status_code)
def get_error_html (self, status_code, **kwargs):
print 'In get_error_html. status_code: ', status_code
if status_code in [403, 404, 500, 503]:
filename = '%d.html' % status_code
print 'rendering filename: ', filename
return self.render_string(filename, title=config.get_title())
return "<html><title>%(code)d: %(message)s</title>" \
"<body class='bodyErrorPage'>%(code)d: %(message)s</body>"\
"</html>" % {
"code": status_code,
"message": httplib.responses[status_code],
}
def prepare (self):
print 'In prepare...'
raise tornado.web.HTTPError(self._status_code)
इबुला, प्रतिक्रिया के लिए धन्यवाद। हनल्डर के लिए write_error() विधि घोषित करके मैं 500s को फंसाने में सक्षम हूं; हालांकि यह दृष्टिकोण वास्तव में साइट पर 404 के संचालन के लिए काम नहीं करता है! तो मुझे आपके द्वारा सुझाए गए एक write_error() विधि के साथ बेस क्लास के अलावा tornado.web.ErrorHandler को आवंटित एक वैश्विक त्रुटि हैंडलर क्लास को गठबंधन करना पड़ा। अब मैं वैश्विक 404 के अलावा, मेरे आवेदन अपवादों को पकड़ने में सक्षम हूं। – Karra