pylons.configuration – Configuration object and defaults setup

Configuration object and defaults setup

The PylonsConfig object is initialized in pylons projects inside the config/ module. Importing the config object from module causes the PylonsConfig object to be created, and setup in app-safe manner so that multiple apps being setup avoid conflicts.

After importing config, the project should then call init_app() with the appropriate options to setup the configuration. In the config data passed with init_app(), various defaults are set use with Paste and Routes.

Module Contents

class pylons.configuration.PylonsConfig

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, and the paths for this instance.

The config object is available in your application as the Pylons global pylons.config. For example:

from pylons import config

template_paths = config['pylons.paths']['templates']

There’s several useful keys of the config object most people will be interested in:

A dict of absolute paths that were defined in the applications config/ module.
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
Whether or not the tmpl_context object should throw an attribute error when access is attempted to an attribute that doesn’t exist. Defaults to True.
Whethor or not Routes variables should automatically be attached to the tmpl_context object when specified in a controllers method.
A dict of Content-Type related default settings for new instances of Request. May contain the values charset and errors and decode_param_names. Overrides the Pylons default values specified by the request_defaults dict.
A dict of Content-Type related default settings for new instances of Response. May contain the values content_type, charset and errors. Overrides the Pylons default values specified by the response_defaults dict.
Mapper object used for Routing. Yes, it is possible to add routes after your application has started running.
init_app(global_conf, app_conf, package=None, paths=None)

Initialize configuration for the application


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
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.
The name of the application package, to be stored in the app_conf.

Changed in version 1.0: template_engine option is no longer supported.