Quoting from the documentation:
Note that when you stream data, the request context is already gone the moment the function executes. Flask 0.9 provides you with a helper that can keep the request context around during the execution of the generator: ...
In your case, your code probably should be:
return Response(stream_with_context(stream_template('login.html', data=delay())))
or
return Response(stream_template('login.html', data=stream_with_context(delay())))