金字塔和.ini配置

金字塔和.ini配置,第1张

金字塔和.ini配置

你当然可以。

在您的入口函数中(

main(global_config,**settings)
__init__.py
大多数情况下),可以在
settings
变量中访问您的配置。

例如,在您的

.ini

[app:main]blog.title = "Custom blog name"blog.comments_enabled = true

在您的

__init__.py

def main(global_config, **settings):    config = Configurator(settings=settings)    blog_title = settings['blog.title']    # you can also access you settings via config    comments_enabled = config.registry.settings['blog.comments_enabled']    return config.make_wsgi_app()

根据最新的Pyramid文档,您可以通过访问视图功能中的设置

request.registry.settings
。而且,据我所知,事件将通过订阅
event.request.registry.settings

关于使用另一个文件的问题,我敢肯定,将所有配置放入常规init文件中是一种很好的做法,就像您一样使用点分符号。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5673416.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存