通过本文主要向大家介绍了tornado,tornado是什么意思,tornado教程,python tornado,tornado下载等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
Tornado 文档中提到但是这样只能捕获到handlers中列出的路径请求中的错误。
如果只定义了(r"/hello", HelloHandler) 一条规则,那么只能捕获到 /hello/other,这样的未定义路径请求,而像/he、/helloworld、/he/other这样的会直接显示Tornado默认的404错误页面,而不会显示自定义的错误页面。
解决方法很简单只需要在路由规则的最后加一条(r".*", BaseHandler),用于捕获未被其他规则捕获的所有请求,然后覆写get方法,并在方法中调用自定义的write_error方法。 例:
def write_error(self, status_code, **kwargs):
if status_code == 404:
self.render('public/404.html')
elif status_code == 500:
self.render('public/500.html')
else:
self.write('error:' + str(status_code))
</div>
您可能想查找下面的文章:
- python 使用get_argument获取url query参数
- python用装饰器自动注册Tornado路由详解
- 使用Python的Tornado框架实现一个Web端图书展示页面
- 深入解析Python的Tornado框架中内置的模板引擎
- 使用Python的Tornado框架实现一个Web端图书展示页面
- 为Python的Tornado框架配置使用Jinja2模板引擎的方法
- Python的Tornado框架实现异步非阻塞访问数据库的示例
- Python的Tornado框架实现图片上传及图片大小修改功能
- Python的Tornado框架的异步任务与AsyncHTTPClient
- 剖析Python的Tornado框架中session支持的实现代码

