Python 使用flask在html页面中编写脚本的输出
我写了一个脚本,使我能够运行一个脚本,然后获得我想要的输出,我试图在一个html页面中编写输出,我如何才能做到这一点?这是我的剧本:Python 使用flask在html页面中编写脚本的输出,python,html,flask,Python,Html,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
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页面来打印运行此脚本的结果吗???在您的视图中。py,在相应的路径下,执行
@app.route('/route_name')
def script_output():
output = execute('./script')
return render_template('template_name.html',output=output)
在你的模板中
<p>{{ output }}</p>
{{output}
非常感谢您,您的回答真的很有帮助!我被困了好几天!!最后一件事,我怎样才能得到一个列表中的输出,我的意思是一些很好的阅读,因为现在我得到的输出显示,但它是在这样一个混乱的一切@siva i收到一个错误未定义的变量'execute'
。你能告诉我我错过了什么吗#juststartedFlask@ans2human,execute
需要定义。请核对问题。