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.
-
Please provide enough code so others can better understand or reproduce the problem.Community– Community Bot2022-10-22 20:42:58 +00:00Commented Oct 22, 2022 at 20:42
-
Perhaps this is what you are looking for?Justin Edwards– Justin Edwards2022-10-23 00:22:37 +00:00Commented Oct 23, 2022 at 0:22
Add a comment
|
1 Answer
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>