Tornado Documentation
› http://www.v2ex.com/tornado/
Tornado on GitHub
› https://github.com/facebook/tornado/
Tornado Gists
› http://tornadogists.org/
fanzeyi
V2EX  ›  Tornado

你们是如何自定义HTTP Error页面的?

  •  
  •   fanzeyi · Jan 11, 2012 · 8550 views
    This topic created in 5418 days ago, the information mentioned may be changed or developed.
    找到两种方法:

    1. 重写 tornado.web.ErrorHandler ... 测试了下这种只能 catch 到普通的 404 错误... 更多的比如 raise tornado.web.HTTPError(404) 这样的就处理不了

    2. 就是在人工 raise 错误前... 生成一个错误页面.. 然后用 nginx 之类的转向到这个页面.. 但是一旦同时出现错误... 会导致各种混乱..

    我觉得这两种方法都不是很完美... 有更好的方法么?

    (正在扒拉Tornado源码的某人..
    7 replies  •  1970-01-01 08:00:00 +08:00
    fanzeyi
    fanzeyi
    OP
    Jan 11, 2012
    1
    简单看了下Tornado的代码.. 似乎可以通过重写 tornado.web.HTTPError 来实现?
    Livid
    Livid
    MOD
    PRO
    Jan 11, 2012
    2
    override write_error
    fanzeyi
    fanzeyi
    OP
    Jan 11, 2012
    3
    @Livid got it.. thanks..

    其实不用重写 write_error ... 直接在 BaseHandler 中提供一个 get_error_html 函数就可以处理了

    get_error_html(self, status_code, **kwargs)

    thanks
    tioover
    tioover
    May 5, 2012
    4
    补充一条,
    如果tornado 没有找到匹配的url最后会出现很丑的默认错误页面
    所以

    http://gist.github.com/2602795
    Janpo
    Janpo
    May 10, 2012
    5
    In Tornado 2.0 and earlier, custom error pages were implemented by overriding RequestHandler.get_error_html, which returned the error page as a string instead of calling the normal output methods (and had slightly different semantics for exceptions). This method is still supported, but it is deprecated and applications are encouraged to switch to RequestHandler.write_error
    CoX
    CoX
    May 10, 2012
    6
    习惯是set_status(404),然后render的,是不是不正规呢?
    fsw90628
    fsw90628
    May 10, 2012
    7
    @livid 这个 http://v2ex.appspot.com/ 有解决办法不?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2991 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 288ms · UTC 05:25 · PVG 13:25 · LAX 21:25 · JFK 00:25
    ♥ Do have faith in what you're doing.