问题描述:

This question already has an answer here:

  • Display data streamed from a Flask view as it updates

    1 answer

网友答案:

The answer to your problems: Flask Streaming

Your route should look something like this:

from flask import stream_with_context, request, Response
from werkzeug import secure_filename

@app.route('/post_files')
def parse_files():
    def generate():
        for file in request.files['file']:
            filename = secure_filename(file.filename)
            yield 'Parsing file ' + filename + ' ...\n'
            parse_file(file) #your external parsing method
    return Response(stream_with_context(generate()))
相关阅读:
Top