[英]Tornado custom error handler for Static file
How can I show custom 404 error page for static files? 如何显示静态文件的自定义404错误页面?
in my current application handler I have added last pattern as follows 在我当前的应用程序处理程序中,我添加了最后一个模式
[
(r'/(favicon.ico)', tornado.web.StaticFileHandler, {"path": mypath}),
(r'/foo',FooHandler),
(r'/bar',BarHandler),
(r'/(.*)',ErrorHandler),
]
and this is my error handler 这是我的错误处理程序
class ErrorHandler(BaseHandler):
def get(self,d):
self.status_code = 404
self.show404(d)
If I visit http://localhost/abc
I am getting my custom 404 page 如果我访问
http://localhost/abc
我将获得自定义404页面
but if I try to get http://localhost/static/abc.js
I'm getting the ugly error like below 但如果我试图获取
http://localhost/static/abc.js
我会得到如下的丑陋错误
line 2286, in validate_absolute_path
raise HTTPError(404)
HTTPError: HTTP 404: Not Found
Is there any way to get this working? 有没有办法让这个工作? How can I show my custom error page for static files
如何显示静态文件的自定义错误页面
This is a bit tricky; 这有点棘手; you need to subclass StaticFileHandler and override its write_error method, then install that class with static_handler_class Application setting.
您需要子类化StaticFileHandler并覆盖其write_error方法,然后使用static_handler_class应用程序设置安装该类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.