嗨,我在ndb中插入了一条记录。我成功地获得了它的url安全密钥。现在,基于这个键,我想查询ndb来获取记录。我怎么能做到这一点。请帮忙。
获取URL安全密钥的代码。
user = Users()
user.name = name
user.email = email
user.password = hashedPass
user.ekey = conkey
user.status = 0
ke = user.put()
chk = ke.urlsafe() // got Key Successfully
现在,基于这个键,我想查询数据库。我怎么能做到这一点。
您可以根据密钥的urlsafe构造函数参数重建密钥,然后调用Key.get
来获取实体:
from google.appengine.ext import ndb
key = ndb.Key(urlsafe=chk) # chk is the same string returned from ke.urlsafe() in your example code
entity = key.get()