0

In Python I would like to render a python variable "myVariable" - which is already in my workspace - to an html template with flask. I just want to render one single html page to copy paste the source code and publish that on a webserver elsewhere. My code renders local variables but I cannot find a solution for passing workspace variables to the render function.

My template (home.html):

<html>
<head>
<title>Some title</title>
</head>
<body>
<p>My variable = {{ myVariable }}. </p>
</body>
</html>

My python code:

from flask import Flask, render_template
app = Flask(__name__)

@app.route('/')

def somfun():
    #myVariable = 12345 #**working... but how to use already existing workspace variable?**
    return render_template("home.html", myVariable=myVariable)

if __name__ == '__main__':
    app.run()
5
  • 1
    What is an 'existing workspace variable'? Commented Jul 21, 2022 at 9:32
  • 1
    What do you mean by a workspace variable? Where is myVariable defined? Commented Jul 21, 2022 at 9:32
  • Try look here where it was already answered <stackoverflow.com/questions/40895329/…> Commented Jul 21, 2022 at 9:33
  • by "workspace variable" I mean a variable that can be seen in the variable explorer. With regard to this question I would just type myVariable = 12345 in the console. Then I would like to run my flask app using this variable... Commented Jul 21, 2022 at 9:48
  • Do you mean an environment variable or an argument, like sys.argv? I don't know which workspace you're referring to. Commented Jul 23, 2022 at 1:36

0

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.