Setting a property from the Pylons .ini file
Let's say I have a settings.py
file in my app's root folder (/myapp/myapp/settings.py
) with just a bu开发者_StackOverflow中文版nch of variables in it:
var1 = ''
var2 = ''
Can I automatically set one of those variables from the .ini
file? I tried this:
myapp.settings.var1 = 'this is from development.ini'
But when I call var1
it is still the empty string:
import myapp.settings as s
print s.var1
I know that I can do var1 = config.get('myapp.settings.var1')
in settings.py
but that just doesn't seem as elegant to me :).
You can find relevant information at this page:
Getting Data from the Configuration File
.ini
is one way only communication. Django uses settings.py which is a normal python module that can be manipulated on-the-fly (causing many obscure errors). Setup your settings in .ini
and use config.get
to access variables.
精彩评论