简体   繁体   中英

How to use a common ini configuration (between development and production) in pyramid?

I want to have a common configuration with settings that do not change across different environments (development and production). I know I could set up a global settings.py file (eg, sql limits), but as far as I know, pyramid requires certain settings to be found in the ini file at startup (eg, template directory paths).

Can I, and if so, how do I would do this in pyramid?

There are a couple possible options without going outside the INI-confines of PasteDeploy. However, up front, realize the beauty of the INI file model is an underlying ability to create multiple files with different settings/configurations. Yes, you have to keep them in sync, but they are just settings (no logic) so that shouldn't be insurmountable.

Anyway, PasteDeploy supports a default section that is inherited by the [app:XXX] sections. So you can place common settings there, and have a different [app:myapp-dev] and [app:myapp-prod] sections.

# settings.ini

[DEFAULT]
foo = bar

[app:myapp-dev]
use = egg:myapp

[app:myapp-prod]
use = egg:myapp

set foo = baz

This can be run via

env/bin/pserve -n myapp-dev settings.ini

Another option is to use multiple configuration files.

# myapp.ini

[app:myapp-section]
use = egg:myapp

foo = bar

# myapp-dev.ini

[app:main]
use = config:myapp.ini#myapp-section

foo = baz

# myapp-prod.ini

[app:main]
use = config:myapp.ini#myapp-section

This can be run via

env/bin/pserve myapp-prod.ini

If you don't want to use PasteDeploy (ini files), you can do something in Python but there are real benefits to this configuration being simple.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM