当前位置: 动力学知识库 > 问答 > 编程问答 >

ajax - Dynamically and constantly push data from Flask to the web browser (i.e. print statements or flash messages)

问题描述:

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()))
分享给朋友:
您可能感兴趣的文章:
随机阅读: