Tornado Error Handling

六月ゝ 毕业季﹏ 提交于 2019-12-05 11:01:18

To provide a custom 404 page make a handler that calls self.set_status(404) (in addition to producing whatever output you want) and set it as default_handler_class in the Application constructor keyword arguments.

class My404Handler(RequestHandler):
    # Override prepare() instead of get() to cover all possible HTTP methods.
    def prepare(self):
        self.set_status(404)
        self.render("404.html")

app = Application(..., default_handler_class=My404Handler)

You probably don't want to use ErrorHandler: it's an easy way to return a specified status code but it doesn't give you control of the output.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!