Мой код:
models.py
from flask_mongoengine import MongoEngine, QuerySet
import datetime
db = MongoEngine()
class Service(db.Document):
service_name = db.StringField(max_length=50, required=True)
date_created = db.DateTimeField(default=datetime.datetime.utcnow)
meta = {
'ordering': ['-date_created'], 'strict' : False
}
class Organisation(db.Document):
org_name = db.StringField(max_length=50, required = True)
service = db.ReferenceField(Service, reverse_delete_rule='CASCADE', required=True)
date_created = db.DateTimeField(default=datetime.datetime.utcnow)
meta = {
'ordering': ['-date_created'], 'strict' : False
}
API (rout.py)
@service.route('/services/<name>', methods=['GET'])
def get_one_service(name):
s = Service.objects(service_name=name)
if s:
output = {'service_name' : s.service_name}
else:
output = "No such name"
return jsonify({'result' : output})
Метод get_one_service()
возвращает вышеупомянутую ошибку.Согласно документации, это правильно.