![](/img/trans.png)
[英]Flask/Python - How can I run this python script in Flask and render output in html page
[英]Write the output of a script in a html page using flask
我寫了一個腳本,使我能夠運行一個腳本,然后獲得想要的輸出,我試圖在html頁面中編寫輸出,我該怎么做? 這是我的腳本:
def execute(cmd):
os.system(cmd)
to_return =dict()
for filename in files:
with open(filename, 'r') as f:
data = f.read()
to_return[filename] = data
return to_return
output = execute('./script')
print output
任何有關如何生成HTML頁面的想法,可以在其中打印運行此腳本的結果?
在您的views.py中,在相應的路線下,執行
@app.route('/route_name')
def script_output():
output = execute('./script')
return render_template('template_name.html',output=output)
在您的模板中
<p>{{ output }}</p>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.