I'm trying to get the variable from the python file to be in the HTML code when rendered using flask, but it isn't printing anything and I have no idea what to do to fix it.
Languages: HTML, Jinja, Python, SQL. I'm using flask on VS code in windows 10. The Python code from "app.py":
@app.route("/")
@login_required
def index():
"""Show portfolio of stocks"""
if (session["user_name"] == None):
render_template("index.html")
else:
user = session["user_name"]
user_info = db.execute('SELECT * FROM users WHERE username IN (?)', user)
print(f"{user_info}")
user_history = db.execute('SELECT * FROM history where username in (?)', user)
if (len(user_info) != 1):
return apology("Server Error, contact us!", 403)
return render_template("indexed.html", info = user_info, history = user_history)
And what the python code is printing in terminal:
{'id': 4, 'username': 'Lychas', 'hash': 'sha256$h7OPyrVIl05k8dNP$a71b6eeec4c3e72ad94a452b423de913b49716c9f923b887e0978189d2091076', 'cash': 10000}]
The HTML line:
<h1 id = "headerone"> Welcome {{ info.username }}, you have {{ info.cash }}$ in your account.</h1>
it should work but it isn't for some reason and I have no idea how to fix it. as you can see the terminal is showing that the db.execute command is working just fine and it should be imported into the rendered HTML but it isn't for some reason and it doesn't raise any errors in chrome as well so I have no idea what's wrong.(you can see the HTML webpage in the background, Python of the left and HTML on the right)
CodePudding user response:

