通过来自 ndb 的 urlsafe 键查询记录 python

Query records through urlsafe key from ndb python

嗨,我在 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()