Most web servers (e.g. FCGI / SCGI) do their own buffering, HTTP clients do their own, etc. It is very difficult to actually get the data uploaded this way, and in order for the client to actually receive it, because this is not a typical operation.
The closest thing to what you are trying to do is pass HttpResponse to the iterator and do the work in the generator; something like that:
def index(request): def do_work(): step_1() yield "step 1 complete" step_2() yield "step 2 complete" step_3() yield "step 3 complete" return HttpResponse(do_work())
... but this will not necessarily be short-lived. (Not verified code, but you get this idea, see http://docs.djangoproject.com/en/dev/ref/request-response/#passing-iterators .)
Most of the infrastructure simply does not expect a phased response. Even if Django is not buffered, it could be your external server, and probably the client too. That is why in most cases additional updates are required for this: a separate interface for requesting the status of a long-term request.
(I would like to be able to do reliable push updates for this kind of thing ...)
Glenn maynard
source share