英文:
URLSafe datastore key for Google Cloud Datastore Entity
问题
我正在尝试获取Google Cloud Datastore实体的“URL安全键”。根据文档 - https://support.google.com/cloud/answer/6361641?hl=en - Google Cloud Datastore客户端应该有一个执行相同操作的函数。然而,我无法找到它。有人可以帮助吗?我正在使用Python库。谢谢。
英文:
I am trying to get the "URL-safe key" for a Google Cloud Datastore entity. As per the documentation - https://support.google.com/cloud/answer/6361641?hl=en - the Google Cloud Datastore client should have a function to do the same. However, I am not able to locate it. Can someone help with this? I am using the Python lib. Thank you.
答案1
得分: 1
以下是已翻译的内容:
- 
如果您正在使用Datastore库,您将调用
to_legacy_urlsafe方法(参见源代码)。这意味着您要执行myKey.to_legacy_urlsafe()要将urlsafe字符串转换回键对象,您需要调用
from_legacy_urlsafe方法(参见源代码)。这意味着您要执行google.cloud.datastore.key.Key.from_legacy_urlsafe(<urlsafe_key>) - 
如果您正在使用
捆绑的ndb API,您需要在键上调用urlsafe方法(参见源代码)。这意味着您要执行myKey.urlsafe()要将urlsafe字符串转换回键对象,您需要调用
ndb.Key(urlsafe=<urlsafe_key>)(参见源代码) 
英文:
Assuming you have a key called myKey, following are your options
- 
If you're using the Datastore library, you'll invoke the
to_legacy_urlsafemethod (see source). This means you domyKey.to_legacy_urlsafe()To convert a urlsafe string back to key object, you call
from_legacy_urlsafemethod (see source). This means you dogoogle.cloud.datastore.key.Key.from_legacy_urlsafe(<urlsafe_key>) - 
If you're using the
bundled ndb API, you invoke theurlsafemethod on a key (see source). This means you domyKey.urlsafe()To convert a urlsafe string back to key object, you call
ndb.Key(urlsafe=<urlsafe_key>)(see source) 
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论