On Sun, 2007-12-23 at 12:12 +0200, Matti Haavikko wrote:
> Malcolm Tredinnick wrote
> > Based on your later, slightly cryptic reply in this thread, I gather you
> > are hoping that HttpResponse is acting as a streamable pipe back to the
> > browser. This isn't correct. You create an HttpResponse instance and
> > when you return from your view, Django will send all of the content back
> > to the user in one go. Nothing happens until you return from the view.
> >   
> There is one way: using a generator you can simulate "streaming". The 
> code below actually sends two chunks of response data in the TCP/IP 
> stream at 1 second interval.
> 
> def example_generator():
>     yield 'foo'
>     time.sleep(1)
>     yield 'bar'
> 
> def my_view():
>     return HttpResponse(dummy_generator())

Definitely not recommended, because it won't work as you expect a lot of
the time. There are a large number of middlewares (including many that
come with Django's core) that cannot on-demand production. This led to
lots of problems when we tried to change template rendering to use
iteration earlier this year.

At some point we need to fix HttpResponse.__init__ so that it
immediately consumes any iterator is passed and stores the content to
avoid subtle bugs in this area.

Regards,
Malcolm

-- 
Experience is something you don't get until just after you need it. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to