Reputation: 766
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>
Upvotes: 5
Views: 2803
Reputation: 2325
You can define variables in app.yaml to make them available to the program's os.environ dictionary:
env_variables:
variable_name: '<YOUR VALUE>'
When you need to use this variable within the main.py you can call it in this way:
import os
CUSTOM_SETTINGS = os.environ['variable_name']
Documentation: https://developers.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_Defining_environment_variables
Upvotes: 3
Reputation: 2033
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.
Upvotes: 10
Reputation: 14213
That's not supported, and you should put your application-specific settings into your own YAML file.
Upvotes: 5