Chunked or streaming page output

84 views
Skip to first unread message

Mike

unread,
Mar 8, 2012, 6:12:39 PM3/8/12
to django...@googlegroups.com
Hi,

Wondering if the limitation (that a page must be completely built in memory before a response is sent) has been rememdied yet. 

Last mention I could find seems to be from almost four years ago:
    https://groups.google.com/d/topic/django-users/BJVZHuIBmSA/discussion

Tom Evans

unread,
Mar 9, 2012, 6:19:54 AM3/9/12
to django...@googlegroups.com

Depending on your needs, you can pass an iterator to HttpResponse in
order to generate chunks on the fly. This works for me using
apache/mod_fastcgi. Something like this:

def myview(request):
def inner():
yield "first chunk"
yield "second chunk"
return HttpResponse(inner())


Obviously this will not work if you require middleware that operates
over the entire response body.

Cheers

Tom

Mike

unread,
Mar 9, 2012, 1:47:51 PM3/9/12
to django...@googlegroups.com
Thank you, I'll give it a try.

P.S.  My email address seems to be embedded in the text ... is that normal?  I really don't want that.  Just a matter of time until the spammers get a hold of it.  Any chance I could delete this thread?

Kurtis

unread,
Mar 9, 2012, 2:39:41 PM3/9/12
to django...@googlegroups.com
Mike,

Your email won't show up as long as you aren't logged in. I'm not saying that it's full-proof, a bot could easily run around logged in to a Google account, but it greatly reduces the chances (I've never had an issue).

Just to add on to Tom's statement concerning the Middleware, one specific middleware that will break things for you is the GZip Middleware, for obvious reasons. This may be a difficult topic to search for but I found quite a few posts previously by searching for terms such as "Django Streaming HttpResponse" -- since I wanted a streaming response instead of just the whole thing dumped out at once.

Good luck!

Mike

unread,
Mar 9, 2012, 3:34:30 PM3/9/12
to django...@googlegroups.com
Hmm, I was able to see my address before logging in, but looking in the source couldn't find it.  Perhaps generated by javascript?  Also I don't see it in your reply, so maybe Tom pasted it in?

I do use the gzip middleware and it doesn't look like there is an easy way to disable it per view.  I did find this bug though:
https://code.djangoproject.com/ticket/7581

Looks like it didn't make it into 1.4 but the discussion ends mentioning 1.3.

Tom Evans

unread,
Mar 9, 2012, 3:46:23 PM3/9/12
to django...@googlegroups.com
On Fri, Mar 9, 2012 at 8:34 PM, Mike <geek...@mgmiller.net> wrote:
> Hmm, I was able to see my address before logging in, but looking in the
> source couldn't find it.  Perhaps generated by javascript?  Also I don't see
> it in your reply, so maybe Tom pasted it in?
>

Most mailers will automatically quote the person they are replying to,
including the time and date of the email, and who sent it, including
their email address.

However you're thinking about the wrong thing. You're using email on a
public mailing list. You've already shared your email address with
every subscriber, and it's been archived on many mailing list archive
websites.

Some archives may obfuscate all email addresses like google groups
does, but there is no guarantee. Eg:

http://python.6.n6.nabble.com/Chunked-or-streaming-page-output-td4560371.html

Cheers

Tom

Reply all
Reply to author
Forward
0 new messages