如何以编程方式获取App Engine项目ID的位置前缀? [英] How can I obtain programatically the location prefix of an App Engine project ID?
问题描述
我正在python 3.7中使用Google App Engine标准,并且需要使用其键为数据存储区中的实体获取旧版安全网址.
I am using Google App Engine standard in python 3.7 and need to obtain the legacy safe url for an Entity in the Datastore using its Key.
为了实现这一点,我需要知道location_prefix.
In order to achieve this I need to know the location_prefix.
如何在Python中以编程方式获取给定项目ID的值?
How can I obtain that value programatically in Python for a given project id?
推荐答案
Is this what you are looking for?: Retrieving Entities from Keys
appengine/standard/GitHub上的/ndb/entities/snippets.pyView
您还可以使用实体的密钥来获取适合的编码字符串嵌入网址:
You can also use an entity's key to obtain an encoded string suitable for embedding in a URL:
url_string = sandy_key.urlsafe()
这将产生类似于"agVoZWxsb3IPCxIHQWNjb3VudBiZiwIM"的结果,以后可用于重建密钥并检索原始实体:
This produces a result like 'agVoZWxsb3IPCxIHQWNjb3VudBiZiwIM' which can later be used to reconstruct the key and retrieve the original entity:
sandy_key = ndb.Key(urlsafe=url_string)
sandy = sandy_key.get()
这篇关于如何以编程方式获取App Engine项目ID的位置前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!