这是一个post
处理程序:
处理程序.py
from imports import logic
@gen.coroutine
def post(self):
data = self.request.body.decode('utf-8')
params = json.loads(data)
model_id= params['model_id']
logic.begin(model_id)
该logic
对象是从 imports.py 中导入的,它是从导入的类中实例化的Logic
进口.py:
import Models
import Logic
class Persist(object):
def getModel(self, model_id):
model = Models.findByModelId(model_id)
return model
persist = Persist()
logic = Logic(persist)
逻辑.py
class Logic(object):
def __init__(self, persist):
self._persist = persist
def begin(self, model_id):
model = self._persist.get_model(model_id)
print ("Model from persist : ")
print (model)
该get_model
方法使用Models
它进行数据库查询并返回未来对象:
模型.py:
from motorengine.document import Document
class Models(Document):
name = StringField(required=True)
def findByModelId(model_id):
return Models.objects.filter(_id=ObjectId(model_id)).find_all()
这将在控制台中打印一个未来对象:
<tornado.concurrent.Future object at 0x7fbb147047b8>
如何将其转换为 json ?