The PylonsConfig class is accessible via the pylons.configuration module.
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 the Pylons global pylons.config. An example usage:
1 2 3 | 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:
{'buffet.template_engines': [],
'buffet.template_options': {},
'debug': False,
'pylons.db_engines': {},
'pylons.environ_config': {},
'pylons.g': None,
'pylons.h': None,
'pylons.package': None,
'pylons.paths': {'controllers': None,
'root': None,
'static_files': None,
'templates': []},
'pylons.request_options': {'charset': 'utf-8',
'decode_param_names': False,
'errors': 'replace',
'language': 'en-us'},
'pylons.response_options': {'charset': 'utf-8',
'content_type': 'text/html',
'errors': 'strict',
'headers': {'Cache-Control': 'no-cache',
'Pragma': 'no-cache'}},
'pylons.strict_c': False}
Add additional template engines for configuration on Pylons WSGI init.
Example of Kid addition:
1 2 3 4 5 6 7 | # 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:
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 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) |
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:
The optional config options in this case are:
Load the environment options
Deprecated functionality for pre-0.9.6 projects.
See the source for more information.