1

This is the flask file

from flask import Flask, redirect, render_template, request
from subprocess import call

app = Flask(__name__) 

@app.route('/')
def mai():
   return render_template('homepage.html')

@app.route('/handle_data', methods=['GET','POST'])  
def home():
    if request.method == "POST":
        projectpath = request.form.get("textinput")
        class Callpy(object):
            def __init__(self,path='test.py'):
                self.path = path
            def call_python_file(self):
                call(['poetry','run','python',f"{self.path}",projectpath])
        c= Callpy()
        output = c.call_python_file()
        if output:
            return render_template('homepage.html',output=output)
    return redirect('/')

if __name__ =='__main__':  
    app.run(debug = True)  

This is the test.py file

import sys
if not sys.argv[1]:
    name = input("hello enter your name : ")
name = sys.argv[1]
def run(name):
    print(f"My name is {name}")
    print(f"My name is {name}")
    print(f"My name is {name}")
    print(f"My name is {name}")
    print(f"My name is {name}")
run(name)

This is the HTML file

<form class="form-horizontal" action="{{ url_for('home')}}" method="post">
    <fieldset>
        <legend>Hello</legend>
        <br>
        <div class="form-group">
            <label class="col-md-4 control-label" for="textinput">Enter your name</label>
            <div class="col-md-4">
                <input id="textinput" name="textinput" type="text" placeholder="" class="form-control input-md"
                    required="">
            </div>
        </div>
        <br>
        <div class="form-group">
            <label class="col-md-4 control-label" for="submit"></label>
            <div class="col-md-4">
                <button id="submit" name="submit" class="btn btn-primary">submit</button>
            </div>
        </div>
        <br>
<div class="logging_window">
    <p>{{ output }}</p>
</div>
    </fieldset>
</form>

<style>
.logging_window{
    display: block;
    padding: 9.5px;
    font-size: 13px;
    line-height: 1.42857143;
    color: #333;
    word-break: break-all;
    word-wrap: break-word;
    background-color: #f5f5f5;
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 50%;
    margin: auto;
}
</style>

After running the flask application in the browser user can enter his name and submit and output must show below in html page but it not working the output i am getting is none i am calling another python file and i need to print that on browser The output is getting printing on console

can anyone help me how to print all this on website with live [1]: https://i.stack.imgur.com/vXO1H.png [2]: https://i.stack.imgur.com/yu9HD.png

Rahul
  • 13
  • 1
  • 5
  • This is offtopic on server fault; it's not about managing systems. However, my suggestion would be to [complete the tutorial](https://flask.palletsprojects.com/en/2.1.x/tutorial/). This will teach you how Flask works. – vidarlo Jun 18 '22 at 22:21

0 Answers0