使用flask将脚本的输出写入html页面 [英] Write the output of a script in a html page using flask

查看:124
本文介绍了使用flask将脚本的输出写入html页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个脚本,使我能够运行一个脚本,然后获得想要的输出,我试图将输出写到html页面中,我该怎么做?这是我的脚本:

I wrote a script that makes me able to run a script and then to get the output I want, I am trying to write the output in a html page, how can I do that? this is my script:

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页面并可以在其中打印运行此脚本的结果的任何想法?

Any Idea of how I can generate an html page where I can print the result of running this script??

推荐答案

在您的views.py中,在相应的路线下,执行

In your views.py, under the corresponding route, do

@app.route('/route_name')
def script_output():
    output = execute('./script')
    return render_template('template_name.html',output=output)

在您的模板中,

<p>{{ output }}</p>

这篇关于使用flask将脚本的输出写入html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆