如何以编程方式获取App Engine项目ID的位置前缀? [英] How can I obtain programatically the location prefix of an App Engine project ID?

查看:59
本文介绍了如何以编程方式获取App Engine项目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.

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

如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆