-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.

2
  • Please provide enough code so others can better understand or reproduce the problem. Commented Oct 22, 2022 at 20:42
  • Perhaps this is what you are looking for? Commented Oct 23, 2022 at 0:22

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

Comments

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.