I am creating a single page web application using Flask's micro-framework.
I have SQL procedures implemented within the database to handle the log in and registration of users.
I am trying to retrieve the name of the user that has logged in and print a welcome message to that users profile page, upon login.
This is the python script so far, It is trying to retrieve all user_name(s) from tbl_user and print them to the userHome page.
app.py
@app.route('/userHome')
def userHome():
if session.get('user'):
return render_template('userHome.html')
cursor1 = db.cursor()
cursor1.execute("select user_name from tbl_user")
result = cursor1.fetchall()
for row in result:
print (row[0])
else:
return render_template('error.html',error = 'Unauthorized Access')
cursor.close()
con.close()
userHome.html (section in which I would like to print user's user_name)
<body style="border:1px solid blue;background:#ffffff;">
<div class="row" style="padding-right:20px;">
<!--PROFILE PIC Section-->
<div class="col-md-3 col-md-offset-1">
<div style="background:#f2f2f2;box-shadow: 10px 10px 30px #333333;margin-right:;">
<img class="" src="http://jnrgym.com/wp-content/uploads/2013/08/Facebook-no-profile-picture-icon-620x389.jpg" style="width:100%;max-height:100%;padding:5%;">
<p style="border:1px solid red;text-align:center;">
{user_name} << this is where I would like user_name to appear
</p>
</div>
</div>
<body>
I am aware that this is not the the correct method to achieve the desired outcome, however this is my first time ever using python. My question is how do I pass the result/output from my python script to my HTML page? (or at the very least print it to the chrome console )
returnshould be at the end of yourviewreturnafter yourifrenders the remaining code useless. You'll want to run the other code prior to running any return.