我是python新手,我正在尝试将数据添加到集合中:import pymongo
from bson.objectid import ObjectId
client = pymongo.MongoClient("mongodb://localhost:27017/")
db = client['inventory']
collection = db['items']
class Inventory():
def insert(self, data):
response = collection.insert_one(data)
return response.inserted_id
然而,我一直得到同样的错误:
^{pr2}$
我相信解决办法很简单,但我似乎找不到。我很感激你的帮助。在
编辑:
应amanb的要求,这是我的路线和索引。在
索引:from flask import Flask, request
from src.routes.inventory import inventory_route
app.register_blueprint(inventory_route, url_prefix='/inventory')
if __name__ == '__main__':
app.run(debug=True)
路线:from flask import Flask, Blueprint
from src.controllers.inventory import inventoryController
controller = inventoryController()
inventory_route = Blueprint('inventory_route', __name__)
@inventory_route.route("/addItem", methods=['POST'])
def addItem():
response = controller.addItem()
return response