INI文件

Pyramid 应用程序中的“【app:main】”部分有不同于 Pylons 对应部分的选项。以下是 Pyramid 的“炼金术”脚手架的外观:

 1[app:main]
 2use = egg:{{project}}
 3
 4pyramid.reload_templates = true
 5pyramid.debug_authorization = false
 6pyramid.debug_notfound = false
 7pyramid.debug_routematch = false
 8pyramid.debug_templates = true
 9pyramid.default_locale_name = en
10pyramid.includes =
11    pyramid_debugtoolbar
12    pyramid_tm
13
14sqlalchemy.url = sqlite:///%(here)s/{{project}}.db

“pyramid.includes=”变量列出了一些要激活的“tweens”。Tween就像一个WSGi中间件,但特定于Pyramid。”Pyramid形“debug toolbar”是调试工具栏;它在每个页面上提供有关请求变量和运行时状态的信息。

"pyramid_tm" is a transaction manager. This has no equivalent in Pylons but is used in TurboGears and BFG. It provides a request-wide transaction that manages your SQLAlchemy session(s) and potentially other kinds of transactions like email sending. This means you don't have to call DBSession.commit() 在你看来。At the end of the request, it will automatically commit the database session(s) and send any pending emails, unless an uncaught exception was raised during the session, in which case it will roll them back. It has functions to allow you to commit or roll back the request-wide transaction at any time, or to "doom" it to prevent any other code from committing anything.

其他“pyramid.*”选项用于调试。将其中任何一个设置为true,以告诉该子系统记录它正在做什么。消息将在调试级别记录。(这些不在ini文件底部的日志配置中的原因是,它们是在采用ini样式的日志配置之前,在Pyramid的历史早期建立的。)

如果“pyramid.reload_templates=true”,模板引擎将在每次呈现模板时检查模板源文件的时间戳,如果模板源已更改,则重新编译模板。这仅适用于支持此功能的模板引擎和Pyramid模板适配器。Mako和 Chameleon 。

“sqlAlchemy.url=”line用于sqlAlchemy。“%(此处)s“扩展到包含ini文件的目录的路径。您可以为任何了解它们的库添加设置,包括sqlacalchemy、mako和beaker。您还可以定义应用程序代码能够理解的自定义设置,以便您可以使用不同的配置部署它,而无需更改代码。这和 Pylons 的情况一样。

production.ini has the same app settings as 开发公司, 除了“TopIDID-Debug工具栏”TWEN not present, and all the debug settings are false. The debug toolbar must be disabled in production because it's a potential security hole: anybody who can force an exception and get an interactive traceback can run arbitrary Python commmands in the application process, and thus read or modify files or execute programs. So never enable the debug toolbar when the site is accessible on the Internet, except perhaps in a wide-area development scenario where higher-level access restrictions (Apache) allow only trusted developers and beta testers to get to the site.

Pyramid no longer uses WSGI middleware by default. In most cases you can find a tween or Pyramid add-on package that does the equivalent. If you need to activate your own middleware, do it the same way as in Pylons; the syntax is in the PasteDeploy manual . But first consider whether making a Pyramid tween would be just as convenient. Tweens have a much simpler API than middleware, and have access to the view's request and response objects. The WSGI protocol is extraordinarily difficult to implement correctly due to edge cases, and many existing middlewares are incorrect. Let server developers and framework developers worry about those issues; you can just write a tween and be out on the golf course by 3pm.