在我正在构建的金字塔应用程序(称为 pyplay)中,我需要检索我在 development.ini 中的应用程序设置。问题是我试图获取该设置的地方无法访问请求变量(例如,在模块文件的顶层)。
因此,在查看文档中的这个示例之后:http: //docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/configuration/django_settings.html我开始做一些非常简单和硬编码的事情,只是为了让它工作。由于我的 development.ini 有这个部分:[app:main],那么我尝试的简单示例如下:
from paste.deploy.loadwsgi import appconfig
config = appconfig('config:development.ini', 'main', relative_to='.')
但应用程序拒绝启动并显示以下错误:
ImportError: <module 'pyplay' from '/home/pish/projects/pyplay/__init__.pyc'> has no 'main' attribute
所以,我想也许我应该放 'pyplay' 而不是 'main',我继续,但我得到了这个错误:
LookupError: No section 'pyplay' (prefixed by 'app' or 'application' or 'composite' or 'composit' or 'pipeline' or 'filter-app') found in config ./development.ini
在这一点上我有点卡住了,我不知道我做错了什么。有人可以帮我看看如何做到这一点吗?
提前致谢!
编辑:以下是我的 development.ini 文件的内容(注意 pish.theparam 是我想要获取的设置):
###
# app configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
###
[app:main]
use = egg:pyplay
pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en_US.utf8
pyramid.includes =
pyramid_debugtoolbar
pyramid_tm
sqlalchemy.url = mysql://user:passwd@localhost/pyplay?charset=utf8
# By default, the toolbar only appears for clients from IP addresses
# '127.0.0.1' and '::1'.
debugtoolbar.hosts = 127.0.0.1 ::1
pish.theparam = somevalue
###
# wsgi server configuration
###
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6543
###
# logging configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
###
[loggers]
keys = root, pyplay, sqlalchemy
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = INFO
handlers = console
[logger_pyplay]
level = DEBUG
handlers =
qualname = pyplay
[logger_sqlalchemy]
level = INFO
handlers =
qualname = sqlalchemy.engine
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
# "level = WARN" logs neither. (Recommended for production systems.)
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s