ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 02.01.2026

Просмотров: 2663

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

17. ENVIRONMENT VARIABLES AND .INI FILE SETTINGS

17.1 Reloading Templates

When this value is true, templates are automatically reloaded whenever they are modified without restarting the application, so you can see changes to templates take effect immediately during development. This flag is meaningful to Chameleon and Mako templates, as well as most third-party template rendering extensions.

Environment Variable Name

Config File Setting Name

PYRAMID_RELOAD_TEMPLATES

pyramid.reload_templates or

 

 

reload_templates

 

 

17.2 Reloading Assets

Don’t cache any asset file data when this value is true. See also Overriding Assets.

Environment Variable Name

Config File Setting Name

PYRAMID_RELOAD_ASSETS

pyramid.reload_assets or reload_assets

latex-note.png

For backwards compatibility purposes, aliases can be used for configurating asset reloading: PYRAMID_RELOAD_RESOURCES (envvar) and pyramid.reload_resources

(config file).

17.3 Debugging Authorization

Print view authorization failure and success information to stderr when this value is true. See also Debugging View Authorization Failures.

Environment Variable Name

Config File Setting Name

PYRAMID_DEBUG_AUTHORIZATIONpyramid.debug_authorization or

 

debug_authorization

 

 

184

17.4. DEBUGGING NOT FOUND ERRORS

17.4 Debugging Not Found Errors

Print view-related NotFound debug messages to stderr when this value is true. See also NotFound Errors.

Environment Variable Name

Config File Setting Name

PYRAMID_DEBUG_NOTFOUND

pyramid.debug_notfound or debug_notfound

17.5 Debugging Route Matching

Print debugging messages related to url dispatch route matching when this value is true. See also Debugging Route Matching.

Environment Variable Name

Config File Setting Name

PYRAMID_DEBUG_ROUTEMATCH

pyramid.debug_routematch or debug_routematch

17.6 Preventing HTTP Caching

Prevent the http_cache view configuration argument from having any effect globally in this process when this value is true. No http caching-related response headers will be set by the Pyramid http_cache view configuration feature when this is true. See also Influencing HTTP Caching.

Environment Variable Name

Config File Setting Name

PYRAMID_PREVENT_HTTP_

CACHEpyramid.prevent_http_cache or

 

prevent_http_cache

17.7 Debugging All

Turns on all debug* settings.

Environment Variable Name

Config File Setting Name

PYRAMID_DEBUG_ALL

pyramid.debug_all or debug_all

185



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