如何在金字塔中使用通用的ini配置(在开发和生产之间)? [英] How to use a common ini configuration (between development and production) in pyramid?

查看:77
本文介绍了如何在金字塔中使用通用的ini配置(在开发和生产之间)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有一个通用配置,且其设置在不同环境(开发和生产)中不会更改.我知道我可以设置一个全局settings.py文件(例如sql限制),但是据我所知,金字塔要求在启动时在ini文件中找到某些设置(例如模板目录路径).

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 (e.g., sql limits), but as far as I know, pyramid requires certain settings to be found in the ini file at startup (e.g., template directory paths).

我可以吗,如果可以的话,我该如何在金字塔中做到这一点?

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

推荐答案

有两种可能的选择,而不会超出PasteDeploy的INI限制.但是,首先要意识到INI文件模型的美感是创建具有不同设置/配置的多个文件的基本能力.是的,您必须使它们保持同步,但是它们只是设置(没有逻辑),所以这不应是无法克服的.

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.

无论如何,PasteDeploy 支持由 [app:XXX] 部分.因此,您可以在此处放置通用设置,并使用不同的 [app:myapp-dev] [app:myapp-prod] 部分.

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

这可以通过

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

这可以通过

env/bin/pserve myapp-prod.ini

如果您不想使用PasteDeploy(ini文件),则可以在Python中做一些事情,但是这种配置简单却有真正的好处.

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.

这篇关于如何在金字塔中使用通用的ini配置(在开发和生产之间)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆