Wednesday, February 27, 2013

Re: StreamingHttpResponse into a Template

Hi, thank you for the answer.
basically what i've to do is to iterate the same operation for a bunch of user (e.g. send an email). 
i've around 200 users and each mail takes 2 seconds. 
so 400 seconds in total and the server goes in timeout. Have to wait 400 seconds on a blank page is not really nice as well.

what i want to do is to stream out to a page an info that a new email was sent. This will avoid the timeout (i guess) and i can keep track of the job. 




On Wed, Feb 27, 2013 at 6:32 PM, Masklinn <masklinn@masklinn.net> wrote:
On 2013-02-27, at 18:23 , Stefano Tranquillini wrote:
> Django 1.5 is just came out and it ships the StreamingHttpResponse.
>
> What i want to do is to print the output of a stream response into a
> template

I'm pretty sure that doesn't make sense: the template has to be
rendered, and I'm pretty sure a given Django template doesn't render to
a stream given https://code.djangoproject.com/ticket/13910 is still
open.

What you *can* do is work the other way around, create a
StreamingHttpResponse and fill it with multiple renderings of a template.

> , having for example a bar that grows based on the streamed data
> (something similar to a loading bar).

If your render target is HTML, that doesn't make any sense either.
That's just not how HTML works. You might be able to send a CSS
stream with incremental rules overwriting one another and growing
a "loading bar", but that's abuse of the whole thing and not of
much use.

> so far i've found a solution that basically is to write the pieces of the
> final html page into the generator function, so each yield does a
> render_to_text of a piece of the final html page (i splitted it manually)
> putting each time the data just processed.
>
> The problem of this solution is that i can't have the loading bar. What I'm
> able to have are incremental data, so i can print out the list of processed
> data, but it's different to what i want to do.
>
> Is there a way to do what i would like to do?

Think about it again and explain what you're originally trying to
achieve. You seem to be approaching the problem from the wrong
direction, as far as I can read.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/eQ2SVB_uYuE/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.





--
Stefano

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment