1

I am having trouble passing a document from my MongoDB database to an HTML file I have rendered using flask. My database is called users and has fields "_id", "name", "username", and "score" in it. I want to set up an HTML page for the profile of a user who is currently logged into the session. so I wrote it like this in my flask app.py:

@app.route("/profile", methods=["GET","POST"])
def profile():
   user = mongo.db.users.find({'username': session['username']})
   return render_template("profile.html", user=user)

Here I am trying to find the document in the database where the username is equal to the current username in the session, and then I pass that to my HTML page. Then in my HTML page I have this:

<body>
    <h1>Your Profile</h1>
    <p>{{ user['name'] }}</p>
    <p>{{ user['score'] }}</p>
            
</body>

But when I look at this on my local server while logged in, nothing shows up. Is my syntax correct? Can anyone tell me what I have wrong?

rachelo
  • 31
  • 1
  • 5

0 Answers0