<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Mongodb MotorMongoDB 的 Python 驅(qū)動

          聯(lián)合創(chuàng)作 · 2023-09-30 19:35

          Motor 為 Tornado 提供了一個基于回調(diào)和 Future 機制的非堵塞的 MongoDB 驅(qū)動程序。Motor 封裝了 PyMongo

          安裝:$ pip install motor

          示例代碼:

          from tornado import gen
          
          class NewMessageHandler(tornado.web.RequestHandler):
              @tornado.web.asynchronous
              @gen.coroutine
              def post(self):
                  """Insert a message."""
                  msg = self.get_argument('msg')
                  db = self.settings['db']
          
                  # insert() returns a Future. Yield the Future to get the result.
                  result = yield db.messages.insert({'msg': msg})
          
                  # Success
                  self.redirect('/')
          
          
          class MessagesHandler(tornado.web.RequestHandler):
              @tornado.web.asynchronous
              @gen.coroutine
              def get(self):
                  """Display all messages."""
                  self.write('<a href="/compose">Compose a message</a><br>')
                  self.write('<ul>')
                  db = self.settings['db']
                  cursor = db.messages.find().sort([('_id', -1)])
                  while (yield cursor.fetch_next):
                      message = cursor.next_object()
                      self.write('<li>%s</li>' % message['msg'])
          
                  # Iteration complete
                  self.write('</ul>')
                  self.finish()

          Motor API

          瀏覽 14
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  免费黄色视频在线观看 | 香蕉性爱网| 无码在线视频播放 | 天天色天天干天天色 | 囯产精品久久久久久久久久 |