how to delete NDB entity using ID?

我们两清 提交于 2019-12-19 06:57:08

问题


based on this docs https://developers.google.com/appengine/docs/python/ndb/entities#deleting_entities well, im still not sure why i cannot do the delete on NDB:

def get(self):
  id = self.request.get("delete")
  ndb.Key('category', id).delete()

yeah i know how to select using id

ndb.Key('category', id).get()

but its still not working...

key = ndb.Key('category', id).get()
key.delete()

this one also not working:

category.key.delete()

something wrong?


回答1:


Try this:

ndb.Key(category, int(id)).delete()

You need to convert the id to integer in order to build a numeric (id) key instead of a name key.



来源:https://stackoverflow.com/questions/11948901/how-to-delete-ndb-entity-using-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!