How to stream an HttpResponse with Django

Posted by muudscope on Stack Overflow See other posts from Stack Overflow or by muudscope
Published on 2010-05-27T16:21:20Z Indexed on 2010/05/27 16:51 UTC
Read the original article Hit count: 216

Filed under:
|
|

I'm trying to get the 'hello world' of streaming responses working for Django (1.2). I figured out how to use a generator and the yield function. But the response still not streaming. I suspect there's a middleware that's mucking with it -- maybe ETAG calculator? But I'm not sure how to disable it. Can somebody please help?

Here's the "hello world" of streaming that I have so far:

def stream_response(request):
    resp = HttpResponse( stream_response_generator())
    return resp

def stream_response_generator():
    for x in range(1,11):
        yield "%s\n" % x  # Returns a chunk of the response to the browser
        time.sleep(1)

© Stack Overflow or respective owner

Related posts about python

Related posts about django