app = Flask(__name__)

@app.route('/')
def index():
    if request.headers.get('accept') == 'text/event-stream':

        def events():
            for i, c in enumerate(itertools.cycle('\\|/-')):
                yield 'data: %s %d\n\n' % (c, i)
time.sleep(0.1)
return Response(events(), content_type='text/event-stream')
return redirect(url_for('static', filename='index.html'))
if __name__ == '__main__':
    app.run(host='localhost', port=23423)
Streaming data with Python and Flask