pylons.configuration
– Configuration object and defaults setup¶Configuration object and defaults setup
The PylonsConfig object is initialized in pylons projects inside the
config/environment.py
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.
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:
pylons.paths
config/environment.py
module.pylons.environ_config
session, cache
pylons.strict_tmpl_context
tmpl_context
object should throw an
attribute error when access is attempted to an attribute that
doesn’t exist. Defaults to True.pylons.tmpl_context_attach_args
pylons.request_options
Request
. May
contain the values charset
and errors
and
decode_param_names
. Overrides the Pylons default values
specified by the request_defaults
dict.pylons.response_options
Response
. May
contain the values content_type
, charset
and
errors
. Overrides the Pylons default values specified by
the response_defaults
dict.routes.map
init_app
(global_conf, app_conf, package=None, paths=None)¶Initialize configuration for the application
global_conf
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:
app_conf
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
Changed in version 1.0: template_engine
option is no longer supported.