Web ページにアクセスできるようにしたいのですが、Python 関数を実行し、進行状況を Web ページに表示します。
そのため、Web ページにアクセスすると、コマンド ラインからスクリプトを実行したかのようにスクリプトの出力が表示され、コマンド ラインで出力が表示されます。
関数で何をする必要がありますか?
テンプレートで何をする必要がありますか?
編集:
Markus Unterwaditzer のコードをテンプレートで使用しようとしています。
{% extends "base.html" %}
{% block content %}
{% autoescape false %}
{{word}}
{% endautoescape %}
{% endblock %}
Python コード
import flask
from flask import render_template
import subprocess
import time
app = flask.Flask(__name__)
@app.route('/yield')
def index():
def inner():
for x in range(1000):
yield '%s<br/>\n' % x
time.sleep(1)
return render_template('simple.html', word=inner())
#return flask.Response(inner(), mimetype='text/html') # text/html is required for most browsers to show the partial page immediately
app.run(debug=True, port=8080)
実行されますが、ブラウザーに何も表示されません。