Re: Request context when passing a generator to Response()
- Joe Shaw
- 2012-11-05 @ 20:28
On Mon, Nov 5, 2012 at 3:17 PM, Joe Shaw <firstname.lastname@example.org> wrote:
> I'd like to use a generator function to return data in a response in
> chunks, but the functions called from that generator require a request
> context because they use url_for().
> By the time the url_for() is called, the request context is long gone.
> Passing in the app and request objects and trying to construct a new
> request context doesn't seem to work. Any ideas?
... and of course I found the answer 10 minutes after sending to the
mailing list, like a true rookie.
New in 0.9 you can wrap the generator in a stream_with_context() and
have the request context available inside the generator.