[英]Streaming HTTP response, flushing to the browser
I've got a view like the following: 我有一个类似以下的视图:
from django.views.decorators.http import condition
def stream():
for i in range(0, 40):
yield " " * 1024
yield "%d" % i
time.sleep(1)
@condition(etag_func=None):
def view(request):
return HttpResponse(stream(), mimetype='text/html')
However, it definitely doesn't seem to be streaming at all. 但是,它似乎根本没有流。 All the data is dumped at once, at the end, after about 40 seconds.
大约40秒后,所有数据立即一次转储。 How can I get it to flush correctly?
如何使它正确冲洗?
To make http streaming work, your middleware, WSGI container, and web server (as well as the reverse-proxy/load-balancer if you use an nginx+apache2 syle deployment) all have to support it. 为了使HTTP流工作,中间件,WSGI容器和Web服务器(以及使用nginx + apache2 syle部署的反向代理/负载均衡器)都必须支持它。 Disable the middleware and remove some of the layers until it works (anything that does caching or sets etags is out), then add them back.
禁用中间件并删除一些层,直到它起作用为止(进行缓存或设置etags的所有操作均已完成),然后将其重新添加。 I don't know what stack you have, but IIRC apache2 + mod_python is OK with streaming, though it's not the recommended way to serve Django.
我不知道您拥有什么堆栈,但是IIRC apache2 + mod_python可以使用流技术,尽管这不是推荐的服务Django的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.