0

I'm developing a Pymongo project using Flask Framework. I want to fetch data and assign it to a variable something like this.

dOcName = select name from doctors where dname = "<some_name>";

Below is my Flask and html code when i run, I'm getting printed <pymongo.cursor.Cursor object at 0x000000000433DB38> in my textbox.

app.py:

@app.route('/dochome',methods=['POST','GET'])
def dochome():
    if request.method == 'POST':
        if len(session) == 0:
            return render_template('login.html')
    uname = session['username']
    dOcName = db.doctors.find({'dname': uname},{'name':1, '_id':0})
    return render_template('dochome.html', dname = uname, dOcName = dOcName)

dochome.html:

<form method="post" action="{{ url_for('dochome') }}">
<div class="container">
    <h3>WELCOME: Doctor. <input class="form-control" type="text" name="docName" value="{{ dOcName }}" readonly></h3>
    </div>
</form>

Any idea what I am doing wrong/how I can get dOcName I am looking for?

Thanks in advance

  • if i use `dOcName = db.doctors.find_one({'dname': uname},{'name':1, '_id':0})` i'm getting result as `{'name': ''}` I want only `` – Syed Burhan May 20 '17 at 02:12
  • Then do `dOcName = db.doctors.find_one({'dname': uname},{'name':1, '_id':0})['name']` and simply access the value of the property in the dict. So it's a duplicate. – Neil Lunn May 20 '17 at 02:18
  • Thanks for your time @NeilLunn I found the result. – Syed Burhan May 20 '17 at 02:45

0 Answers0