Skip to content

Commit

Permalink
Merge pull request #288 from timrichardson/app_config_v2
Browse files Browse the repository at this point in the history
typo and other fixes for appconfig.ini
  • Loading branch information
mdipierro committed Sep 8, 2015
2 parents a1125e4 + 74ee615 commit 7825358
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions sources/29-web2py-english/13.markmin
@@ -1,27 +1,40 @@

## Deployment: development and production
``appconfig``:inxx
[[appconfig]]
### 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 uses the private directory for storing information which is not replicated in a typical deployment to productoin.
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/app_config.ini``
Private directories are ignored by git in the default web2py settings, as the private folder is designed to be a safe place to store sensitive information.

An easy way to learn about this module is to create a new app an inspect the default usage.

By default, app_config.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.
By default, ``app_config.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)``:code

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)
``:code

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 =
``:code

## Deployment recipes: Infrastructure

There are multiple ways to deploy web2py in a production environment. The details depend on the configuration and the services provided by the host.

In this chapter we consider the following issues:
Expand Down

0 comments on commit 7825358

Please sign in to comment.