-1

I want to display what I am printing to the console. ex. print('Hello World') once its printing to the terminal. How can I also display that on my page.

Singh
  • 1

1 Answers1

0

I'm a little confused, but I don't believe it's possible to get a text from the console in flask. The best way to do what you're trying to do is to collect information from flask and import it into your HTML file.

anything you're printing to the console should be turned into a variable, so flask can send it to the HTML page. I also encourage you to look further into these methods before use.

Method One: Function

flask.py

def a: 
    return "print something"

app.jinja_env.globals.update(get_var)

index.html

<p> {{ get_var() }} </p>

Method Two: Session

flask.py

app = Flask(__name__)
app.secret_key = '12345'

app.config["SESSION_TYPE"] = "filesystem"

sess = Session()
sess.init_app(app)

Session(app)
session['print_text']

index.html

<p> {{session['print_text'] </p>