Continuation
Continuation

Reputation: 13040

Is there a function in Django / Python similar to PHP flush() that lets me send part of the HTTP response to clients?

According to the performance tip from Yahoo:

When users request a page, it can take anywhere from 200 to 500ms for the backend server to stitch together the HTML page. During this time, the browser is idle as it waits for the data to arrive. In PHP you have the function flush(). It allows you to send your partially ready HTML response to the browser so that the browser can start fetching components while your backend is busy with the rest of the HTML page.

Example:

   ... <!-- css, js -->
    </head>
    <?php flush(); ?>
    <body>
      ... <!-- content -->

Is there a function in Django/Python that;s simialr to PHP's flush()?

Thanks

Upvotes: 7

Views: 905

Answers (3)

Daniel Roseman
Daniel Roseman

Reputation: 599590

You can yield a partial response instead of returning it.

Upvotes: 2

John Mee
John Mee

Reputation: 52253

No. Is the short answer.

The long answer depends what you're using between the webserver and python: You could implement it with WSGI but it wouldn't be a whimsical task.

Maybe start here? http://www.python.org/dev/peps/pep-0333/#the-start-response-callable

Upvotes: 2

David Fells
David Fells

Reputation: 6798

http://www.evanfosmark.com/2008/06/simple-output-buffering-in-python/ - Good article on the topic. Should do exactly what you need using either option provided.

Upvotes: 2

Related Questions