如何以编程方式获取App

如何以编程方式获取App

本文介绍了如何以编程方式获取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

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的位置前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 07:26