3

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

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

1 Answer 1

12

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)

And in your template,

<p>{{ output }}</p>
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much your answer really helped! I was stuck for days!! Just one last thing, how can I get the output in a list or so, I mean something nice to read, cause now I get the output displayed but it's all in such a mess!
@siva i get an error Undefined variable 'execute'. Can you tell me what i'm missing? #juststartedFlask
@ans2human, execute needs to be defined. Please check the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.