RT,官方文档看的不是很懂:RequestHandler.send_error(status_code=500,kwargs)**SendsthegivenHTTPerrorcodetothebrowser.Ifflush()hasalreadybeencalled,itisnotpossibletosendanerror,sothismethodwillsimplyterminatetheresponse.Ifoutputhasbeenwrittenbutnotyetflushed,itwillbediscardedandreplacedwiththeerrorpage.Overridewrite_error()tocustomizetheerrorpagethatisreturned.Additionalkeywordargumentsarepassedthroughtowrite_error.RequestHandler.write_error(status_code,kwargs)**Overridetoimplementcustomerrorpages.write_errormaycallwrite,render,set_header,etctoproduceoutputasusual.Ifthiserrorwascausedbyanuncaughtexception(includingHTTPError),anexc_infotriplewillbeavailableaskwargs["exc_info"].Notethatthisexceptionmaynotbethe“current”exceptionforpurposesofmethodslikesys.exc_info()ortraceback.format_exc.我理解的是send_error调用了write_error,所以写自定义错误页面的时候要自己实现write_error方法,抛出错误的时候使用send_error。那么又该在什么时候使用rasietornado.web.HTTPError呢?
当年话下
忽然笑
相关分类