Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
pyramid.pdf
Скачиваний:
11
Добавлен:
24.03.2015
Размер:
3.82 Mб
Скачать

17. ENVIRONMENT VARIABLES AND .INI FILE SETTINGS

17.8 Reloading All

Turns on all reload* settings.

Environment Variable Name

Config File Setting Name

PYRAMID_RELOAD_ALL

pyramid.reload_all or reload_all

17.9 Default Locale Name

The value supplied here is used as the default locale name when a locale negotiator is not registered. See also Localization-Related Deployment Settings.

Environment Variable Name

Config File Setting Name

PYRAMID_DEFAULT_LOCALE_

NAMEpyramid.default_locale_name or

 

default_locale_name

 

 

17.10 Including Packages

pyramid.includes instructs your application to include other packages. Using the setting is equivalent to using the pyramid.config.Configurator.include() method.

Config File Setting Name

pyramid.includes

The value supplied as pyramid.includes should be a sequence. The sequence can take several different forms.

1.It can be a string.

If it is a string, the package names can be separated by spaces:

package1 package2 package3

The package names can also be separated by carriage returns::

package1

package2

package3

2. It can be a Python list, where the values are strings:

186

17.10. INCLUDING PACKAGES

[’package1’, ’package2’, ’package3’]

Each value in the sequence should be a dotted Python name.

17.10.1 pyramid.includes vs. pyramid.config.Configurator.include()

Two methods exist for including packages: pyramid.includes and pyramid.config.Configurator.include(). This section explains their equivalence.

Using PasteDeploy

Using the following pyramid.includes setting in the PasteDeploy .ini file in your application:

[app:main]

pyramid.includes = pyramid_debugtoolbar pyramid_tm

Is equivalent to using the following statements in your configuration code:

1 from pyramid.config import Configurator

2

3 def main(global_config, **settings):

4config = Configurator(settings=settings)

5# ...

6config.include(’pyramid_debugtoolbar’)

7config.include(’pyramid_tm’)

8# ...

It is fine to use both or either form.

Plain Python

Using the following pyramid.includes setting in your plain-Python Pyramid application:

187

17. ENVIRONMENT VARIABLES AND .INI FILE SETTINGS

1

2

3

4

5

from pyramid.config import Configurator

if __name__ == ’__main__’:

settings = {’pyramid.includes’:’pyramid_debugtoolbar pyramid_tm’} config = Configurator(settings=settings)

Is equivalent to using the following statements in your configuration code:

1 from pyramid.config import Configurator

2

3 if __name__ == ’__main__’:

4settings = {}

5config = Configurator(settings=settings)

6config.include(’pyramid_debugtoolbar’)

7config.include(’pyramid_tm’)

It is fine to use both or either form.

17.11 Explicit Tween Configuration

This value allows you to perform explicit tween ordering in your configuration. Tweens are bits of code used by add-on authors to extend Pyramid. They form a chain, and require ordering.

Ideally, you won’t need to use the pyramid.tweens setting at all. Tweens are generally ordered and included “implicitly” when an add-on package which registers a tween is “included”. Packages are included when you name a pyramid.includes setting in your configuration or when you call pyramid.config.Configuration.include().

Authors of included add-ons provide “implicit” tween configuration ordering hints to Pyramid when their packages are included. However, the implicit tween ordering is only best-effort. Pyramid will attempt to provide an implicit order of tweens as best it can using hints provided by add-on authors, but because it’s only best-effort, if very precise tween ordering is required, the only surefire way to get it is to use an explicit tween order. You may be required to inspect your tween ordering (see Displaying “Tweens”) and add a pyramid.tweens configuration value at the behest of an add-on author.

Config File Setting Name

pyramid.tweens

The value supplied as pyramid.tweens should be a sequence. The sequence can take several different forms.

188

17.11. EXPLICIT TWEEN CONFIGURATION

1.It can be a string.

If it is a string, the tween names can be separated by spaces:

pkg.tween_factory1 pkg.tween_factory2 pkg.tween_factory3

The tween names can also be separated by carriage returns::

pkg.tween_factory1 pkg.tween_factory2 pkg.tween_factory3

2. It can be a Python list, where the values are strings:

[’pkg.tween_factory1’, ’pkg.tween_factory2’, ’pkg.tween_factory3’]

Each value in the sequence should be a dotted Python name.

17.11.1 PasteDeploy Configuration vs. Plain-Python Configuration

Using the following pyramid.tweens setting in the PasteDeploy .ini file in your application:

[app:main]

pyramid.tweens = pyramid_debugtoolbar.toolbar.tween_factory pyramid.tweens.excview_tween_factory pyramid_tm.tm_tween_factory

Is equivalent to using the following statements in your configuration code:

1 from pyramid.config import Configurator

2

3 def main(global_config, **settings):

4settings[’pyramid.tweens’] = [

5’pyramid_debugtoolbar.toolbar.tween_factory’,

6’pyramid.tweebs.excview_tween_factory’,

7’pyramid_tm.tm_tween_factory’,

8

]

9config = Configurator(settings=settings)

It is fine to use both or either form.

189

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]