我写了一个脚本,使我能够运行一个脚本,然后得到我想要的输出,我正试图写在一个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>

关于python - 使用flask将脚本的输出写入html页面,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35840386/

10-12 07:39
查看更多