流式传输HTTP响应,刷新到浏览器

时间:2010-05-28 22:25:55

标签: django

我的观点如下:

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')

然而,它似乎根本不是流媒体。在大约40秒后,所有数据在最后一次被转储。我怎样才能让它正确冲洗?

1 个答案:

答案 0 :(得分:3)

要使http流工作,您的中间件,WSGI容器和Web服务器(以及反向代理/负载均衡器,如果您使用nginx + apache2 syle部署)都必须支持它。禁用中间件并删除一些层,直到它工作(任何缓存或设置etags的东西都没有),然后再添加它们。我不知道你有什么堆栈,但IIRC apache2 + mod_python可以通过流媒体播放,但不是推荐的Django服务方式。