开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜