从ndb python通过urlsafe键查询记录

2024-04-19 23:59:03 发布

您现在位置: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

现在根据这个键我想查询数据库。我怎么能做到这一点。在


Tags: 代码nameurlemail记录密钥passwordusers
2条回答

您可以根据键的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()

相关问题 更多 >