我想将 mongoengine 与 Flask 一起使用。
from mongoengine import *
connect('db_test', port=27017)
class Client(Document):
name = StringField(required=True, max_length=200,unique=True)
tel_nummer = StringField(required=True)
age = StringField(required=True, max_length=50)
@app.route('/api/clients', methods=['GET'])
def get_clients():
all_clients=Client.objects.all()
return jsonify(result=all_clients.to_json())
输出是:
result "[{\"_id\": {\"$oid\": \"5cdb1ed17218d7a0b5218832\"}, \"name\": \"Tom\", \"telnummer\": \"34634534\", \"age\": \"34534534\",}]"
谢谢。