如何以编程方式获取App Engine项目ID的位置前缀?

问题描述 投票:0回答:1

我正在python 3.7中使用Google App Engine标准,并且需要使用其键为数据存储区中的实体获取旧版安全网址。

为了实现这一点,我需要知道location_prefix。

https://googleapis.dev/python/datastore/latest/_modules/google/cloud/datastore/key.html#Key.to_legacy_urlsafe

如何为给定的项目ID在Python中以编程方式获取该值?

google-app-engine google-app-engine-python
1个回答
0
投票

这是您要寻找的吗?:Retrieving Entities from Keys

appengine/standard/ndb/entities/snippets.pyView on GitHub

您还可以使用实体的密钥来获取适合的编码字符串 用于嵌入网址:

url_string = sandy_key.urlsafe()

这会产生类似于'agVoZWxsb3IPCxIHQWNjb3VudBiZiwIM'的结果,以后可用于重建密钥并检索原始实体:

sandy_key = ndb.Key(urlsafe=url_string)
sandy = sandy_key.get()
© www.soinside.com 2019 - 2024. All rights reserved.