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.
Asked
Active
Viewed 144 times
-1
-
Please provide enough code so others can better understand or reproduce the problem. – Community Oct 22 '22 at 20:42
-
Perhaps [this](https://stackoverflow.com/questions/4408377/how-can-i-get-terminal-output-in-python) is what you are looking for? – Justin Edwards Oct 23 '22 at 00:22
1 Answers
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>

user9158163
- 1
- 2