开发者

Name of Current App in Google App Engine (Python)

开发者 https://www.devze.com 2023-03-02 22:21 出处:网络
Using the Google App Engine Python API is there开发者_如何学运维 a way to access the name of the currently running application--i.e., the app name specified in your app.yaml file with application: foo

Using the Google App Engine Python API is there开发者_如何学运维 a way to access the name of the currently running application--i.e., the app name specified in your app.yaml file with application: foobar?


import os
appname = os.environ['APPLICATION_ID']

EDIT: I just noticed this because I got a new upvote on it today (shame on you, upvoter!), but this is no longer correct.

from google.appengine.api.app_identity import get_application_id
appname = get_application_id()

should be used. The value in os.environ will include a "s~" prefix for applications using the HR datastore and, by default, "dev~" on the development server. (os.environ should also be avoided entirely on App Engine anyway, since when concurrency support is added with the Python 2.7 runtime, use of os.environ won't be threadsafe and will allow data to leak from one request to another, although obviously the application ID itself would be the same for multiple requests to the same application at the same time...)

0

精彩评论

暂无评论...
验证码 换一张
取 消