13. Using your own configuration options

You can store your own configuration options in the config file. Just add your own section and options. Then, in the code, these informations are available through the configFile global variable. This variable is a ConfigParser object. The following is an example on how to use this:
**** File HelloServer.cfg ****
[server]
socketPort=80

[staticContent]
static=/home/remi/static

# Here I add my own configuration options
[user]
name=Remi
[database]
login=remiLogin
password=remiPassword


*** File Hello.cpy ****
CherryClass Root:
view:
    def index(self):
        <html><body>
            Hello, <py-eval="configFile.get('user','name')"><br>
            to connect to the database, you should use:<br>
            <py-eval="'Login:%s, Password:%s'%(configFile.get('database','login'), configFile.get('database','password'))">
        </body></html>
This will be rendered as:
<html><body>
    Hello, Remi<br>
    to connect to the database, you should use:<br>
    Login:remiLogin, Password:remiPassword
</body></html>

In the next chapter, we'll learn about CherryPy's special variables and special functions ...

See About this document... for information on suggesting changes.