Django / Python中是否有类似于PHP flush()的功能,可以将部分HTTP响应发送给客户端? [英] Is there a function in Django / Python similar to PHP flush() that lets me send part of the HTTP response to clients?

查看:119
本文介绍了Django / Python中是否有类似于PHP flush()的功能,可以将部分HTTP响应发送给客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Yahoo的效能提示


当用户请求页面时,
后端服务器可以从200到500ms的任何地方将
HTML页面拼接在一起。在此期间,
浏览器空闲,因为它等待
数据到达。在PHP中,您有
函数flush()。它允许您
发送部分准备的HTML
响应到浏览器,以便
浏览器可以开始提取组件
,而您的后端忙于
其余的HTML页面。

When users request a page, it can take anywhere from 200 to 500ms for the backend server to stitch together the HTML page. During this time, the browser is idle as it waits for the data to arrive. In PHP you have the function flush(). It allows you to send your partially ready HTML response to the browser so that the browser can start fetching components while your backend is busy with the rest of the HTML page.

示例:



   ... <!-- css, js -->
    </head>
    <?php flush(); ?>
    <body>
      ... <!-- content -->

Django / Python中有一个函数,它与PHP的 flush ()

Is there a function in Django/Python that;s simialr to PHP's flush()?

谢谢

推荐答案

无。是简短的答案。

长的答案取决于您在网络服务器和python之间使用的内容:
您可以使用WSGI实现它,但不会是一个异想天开的任务。

The long answer depends what you're using between the webserver and python: You could implement it with WSGI but it wouldn't be a whimsical task.

也许从这里开始?
http://www.python。 org / dev / peps / pep-0333 /#the-start-response-callable

这篇关于Django / Python中是否有类似于PHP flush()的功能,可以将部分HTTP响应发送给客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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