AppConfig module
The environment between your development and production system will almost certainly mean a different database configuration, different mail servers and possibly other differences.
Web2py intends the private directory for storing information which is not replicated in a typical deployment to production (although you need to take care to make sure that you are not deploying that directory).
The contributed module AppConfig
allows the private directory to store a simple configuration text file to define settings which vary between dev and production, such as database connections. By default it is a text file which is pythonesque, but json is also supported.
The welcome app now uses this module in db.py
to read configuration from a file in the application’s private directory. By default the path to this file is
private/appconfig.ini
By default, appconfig.ini
allows you to define a database connection and smtp configuration. When the application is stable, the module can be set to cached mode to reduce overhead.
from gluon.contrib.appconfig import AppConfig
...
myconf = AppConfig(reload=False)
Applications created in a recent version of web2py default to having the database connection defined with AppConfig.
The values in app_config.ini are fetched and cast from a string value by like so:
myconf = AppConfig()
...
a_config_value = myconf.take('example_section.example_key', cast=int)
Because the casting occurs from a string, and non empty strings cast to True, the safest way to represent a Boolean False is with an empty string:
[example_section]
example_key =