Latest Version: 0.9.6.2

Warning

This documentation does not refer to the most recent version of Pylons. Current Documentation

Config

Pylons configuration object

The Pylons configuration object is a per-application instance object that retains the information regarding the global and app conf's as well as per-application instance specific data such as the mapper, the paths for this instance, and the myghty configuration.

The Config object is available in your application as a Pylons global pylons_config under the g object. There's several useful attributes of the config object most people will be interested in:

myghty
The myghty configuration dict that was used to initialize Myghty
map
Mapper object used for Routing. Yes, it is possible to add routes after your application has started running.
paths
An array of absolute paths that were defined in the applications config/environment.py module.
global_conf
Global configuration passed in from Paste, this corresponds to the DEFAULTS section in the config file.
app_conf
Application specific configuration directives, passed in via Paste from the app section of the config file.
environ_config
Dict of environ keys for where in the environ to pickup various objects for registering with Pylons. If these are present then PylonsApp will use them from environ rather than using default middleware from Beaker. Valid keys are: session, cache
template_engines
List of template engines to configure. The first one in the list will be configured as the default template engine. Each item in the list is a dict indicating how to configure the template engine with keys: engine, template_root, template_options, and alias

Methods

f __init__(self, myghty, map, paths, environ_config=None) ...

f add_template_engine(self, engine, root, options, alias=None) ...

Add additional template engines for configuration on Pylons WSGI init

engine
The name of the template engine
root
Template root for the engine
options
Dict of additional options used during engine initialization
alias
Name engine should respond to when actually used. This allows for multiple configurations of the same engine and lets you alias the additional ones to other names.

Example of Kid addition:

# In yourproj/middleware.py
# ...
config.init_app(global_conf, app_conf, package='yourproj')

# Load additional template engines
kidopts = {'kid.assume_encoding':'utf-8', 'kid.encoding':'utf-8'}
config.add_template_engine('kid', 'yourproj.kidtemplates', kidopts)

Example of changing the default template engine:

# In yourproj/middleware.py
# ...
config.init_app(global_conf, app_conf, package='yourproj')

# Remove existing template engine
old_default = config.template_engines.pop()

# Load additional template engines
kidopts = {'kid.assume_encoding':'utf-8', 'kid.encoding':'utf-8'}
config.add_template_engine('kid', 'yourproj.kidtemplates', kidopts)

# Add old default as additional engine
config.template_engines.append(old_default)

f init_app(self, global_conf, app_conf, package) ...

Initialize configuration for the application

global_config

Several options are expected to be set for a Pylons web application. They will be loaded from the global_config which has the main Paste options. If debug is not enabled as a global config option, the following option must be set:

  • error_to - The email address to send the debug error to

The optional config options in this case are:

  • smtp_server - The SMTP server to use, defaults to 'localhost'
  • error_log - A logfile to write the error to
  • error_subject_prefix - The prefix of the error email subject
  • from_address - Whom the error email should be from
app_conf
Defaults supplied via the [app:main] section from the Paste config file. load_config only cares about whether a 'prefix' option is set, if so it will update Routes to ensure URL's take that into account.
package
The name of the application package, to be stored in the app_conf.

See the source for more information.

Top