我写代码如下
from google.appengine.ext import ndb
__metaclass__ = type
class UserSession(ndb.Model):
session = ndb.BlobProperty()
class KV:
@staticmethod
def get(id):
r = ndb.Key(UserSession, int(id)).get()
if r:
return r.session
@staticmethod
def set(id, value):
return UserSession.get_or_insert(int(id), session=value)
@staticmethod
def delete(id):
ndb.Key(UserSession, int(id)).delete()
我写的地方
id = 1
key = ndb.Key(UserSession, int(id))
UserSession.get_or_insert(key, session=1)
sdk 加薪
TypeError: name must be a string; received Key('UserSession', 1)
当我调用 KV.get ()
sdk 加薪
文件“/home/bitcoin/42btc/zapp/_plugin/auth/model/gae/user.py”,第 14 行,在 get
r = ndb.Key(UserSession,int(id)).get()
...
BadRequestError:缺少密钥 ID/名称
那么,如何使用 NDB?