为什么要同时使用 Tornado 和 Flask? [英] Why use Tornado and Flask together?

查看:31
本文介绍了为什么要同时使用 Tornado 和 Flask?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知 Tornado 是一个服务器和一个框架.在我看来,将 Flask 和 Tornado 一起使用就像添加另一个抽象层(更多开销).为什么人们把 Flask 和 Tornado 一起使用,有什么好处?

As far as I can tell Tornado is a server and a framework in one. It seems to me that using Flask and Tornado together is like adding another abstraction layer (more overhead). Why do people use Flask and Tornado together, what are the advantages?

推荐答案

根据这个问题 这是因为 Flask 是阻塞的,而 Tornado 是非阻塞的.

According to this question it is because Flask is blocking and Tornado is non-blocking.

如果使用 Tornado 作为 WSGI 服务器和 Flask 作为 url 路由+ 模板 不应该有任何开销.通过这种方法,您无需使用 Flask 的 Web 服务器,因此实际上并没有额外的抽象层.

If one uses Tornado as a WSGI server and Flask for url routing + templates there shouldn't be any overhead. With this approach you aren't using Flask's web server, so there isn't really an extra layer of abstraction.

然而,如果一个人只将 Flask 用于模板,他们可以将 Tornado 与 Jinja2 一起使用,这是Flask 使用的模板引擎.

However, if one is using Flask just for the templates they could use Tornado with Jinja2 which is the template engine that Flask uses.

这篇关于为什么要同时使用 Tornado 和 Flask?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆