Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a variable from app.yaml to main.py with Google App Engine Python

I am trying to pass some configuration variables to my main.py from app.yaml. I haven't been able to locate the syntax for accessing app.yaml from the code.

For example you want to have the user put their client number in app.yaml and access it from main.py to pass into main.html. While it would be easy to create a variable in main.py to pass it, it seems to be something that would be better put into app.yaml.

Example:

app.yaml

    application: xyz
    version: 1
    runtime: python27
    ...
    clientID: (ID here)

main.py

    myID = appYAML.clientID
    ...
    values = {'xyz': blah.blah, 'myID': myID }

main.html

    ...
    <script>
      ...
      {% ifequal myID %}
        my_client = {{myID}}
      ...
    </script>
like image 487
Mark Finch Avatar asked Apr 23 '12 18:04

Mark Finch


2 Answers

With the 1.6.5 release, App Engine support this[1]:

- In your app.yaml file, you can include an env_variables stanza that will set
  the given environment variables in your application's runtime.

Information on how to use this is available at: https://cloud.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_Defining_environment_variables.

like image 118
schuppe Avatar answered Nov 08 '22 16:11

schuppe


That's not supported, and you should put your application-specific settings into your own YAML file.

like image 41
Adam Crossland Avatar answered Nov 08 '22 17:11

Adam Crossland