I am trying to make a flask app that can support user login request and return data from the mongodb database, after it receives password and username which match with the entry in the database. Although, it is returning me empty value as a result of the find query, prompting null object error at output line, even if the data is present in the database. Also, the code isn't getting inside the 'for loop'.
from flask import Flask, render_template
import pymongo
from flask import jsonify, request
from flask_pymongo import PyMongo
app= Flask(__name__)
app1= Flask(__name__)
app.config['MONGO_DBNAME']= 'VendorDetails'
app.config['MONGO_URL']='mongodb://localhost:27017/VendorDetails'
mongo=PyMongo(app)
@app.route('/getvendorlogin', methods=['POST'])
def getVendorLogin():
vendor=mongo.db.VendorDetails.VendorDetails
Username= request.json["Username"]
Password= request.json["Password"]
v= vendor.find({'Username':Username},{'Password':Password})
for record in v:
Username1= record['Username']
Password1= record['Password']
Name1= record['Name']
output= {"Username":Username1, "Password":Password1, "Name":Name1}
return jsonify({'result':output})
if __name__=="__main__":
app.run(host='0.0.0.0', port=80)
Name of my database is 'VendorDetails' and name of my collection is also 'VendorDetails'. Please suggest me possible way to solve this.
try to change this line :
v= vendor.find({'Username':Username},{'Password':Password})
to this one:
v= vendor.find({"Username": Username, "Password":Password})
let me know if it work.