擅长:python、mysql、java
<p>我认为如果要使用这样的模板,可能需要使用这里给出的<code>stream_template</code>函数:<a href="http://flask.pocoo.org/docs/patterns/streaming/#streaming-from-templates" rel="nofollow noreferrer">http://flask.pocoo.org/docs/patterns/streaming/#streaming-from-templates</a></p>
<p>我没有测试这个,但可能看起来像:</p>
<pre><code>def stream_template(template_name, **context):
app.update_template_context(context)
t = app.jinja_env.get_template(template_name)
rv = t.stream(context)
rv.enable_buffering(5)
return rv
@app.route('/scans/')
def scans_query():
url_for('static', filename='.*')
def generate():
for i in xrange(50):
sleep(.5)
yield i
return Response(stream_template('scans.html', i=generate()))
</code></pre>