Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

root/branches/cherrypy-2.1/docs/book/xml/configsystemoverview.xml

Revision 683 (checked in by fumanchu, 3 years ago)

Doc updates for [682] (error-handling changes).

Line 
1 <?xml version="1.0" encoding="UTF-8"?>
2 <section xmlns:db="http://docbook.org/docbook-ng"
3          xmlns:xi="http://www.w3.org/2001/XInclude"
4          xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5          xml:id="configsystemoverview">
6   <title>Configuration system overview</title>
7   <para>The CherryPy configuration system provides fine-grained control over
8   how each part of the application should react. You will use it for two
9   reasons:</para>
10   <itemizedlist>
11     <listitem>Web server settings</listitem>
12     <listitem>Enabling filters per path</listitem>
13   </itemizedlist>
14   <para>You will be able to declare the configuration settings either from a
15   file or from a Python dictionary.</para>
16   <para>First of all, let's see how a typical configuration file is
17   defined.</para>
18   <example>
19     <title>Configuration file</title>
20     <programlisting linenumbering="numbered">
21             # The configuration file called myconfigfile.conf
22             [global]
23             server.socketPort=8080
24             server.socketHost=""
25             server.socketFile=""
26             server.socketQueueSize=5
27             server.protocolVersion="HTTP/1.0"
28             server.logToScreen=True
29             server.logFile=""
30             server.reverseDNS=False
31             server.threadPool=10
32             server.environment="development"
33            
34             [/service/xmlrpc]
35             xmlRpcFilter.on = True
36            
37             [/admin]
38             sessionAuthenticateFilter.on=True
39            
40             [/css/default.css]
41             staticFilter.on = True
42             staticFilter.file = "data/css/default.css"
43            
44             # From your script...
45             cherrypy.config.update(file="myconfigfile.conf")
46         </programlisting>
47   </example>
48   <para>The settings can also be defined using a python dictionary instead of
49   a file as follows:</para>
50   <example>
51     <title>Configuration dictionary</title>
52     <programlisting linenumbering="numbered">
53       settings = {
54          'global': {
55             'server.socketPort' : 8080,
56             'server.socketHost': "",
57             'server.socketFile': "",
58             'server.socketQueueSize': 5,
59             'server.protocolVersion': "HTTP/1.0",
60             'server.logToScreen': True,
61             'server.logFile': "",
62             'server.reverseDNS': False,
63             'server.threadPool': 10,
64             'server.environment': "development"
65          },
66          '/service/xmlrpc' : {
67             'xmlRpcFilter.on': True
68          },
69          '/admin': {
70             'sessionAuthenticateFilter.on' :True
71          },
72          '/css/default.css': {
73             'staticFilter.on': True,
74             'staticFilter.file': "data/css/default.css"
75          }
76       }
77       cherrypy.config.update(settings)
78         </programlisting>
79   </example>
80   <para>Each section of the configuration refers to a URL path; each path is
81   mapped to a published object of the tree handled by CherryPy. Therefore when
82   the server receives a request for <code>/css/default.css</code>, the static
83   filter will be called and the server will actually return the physical file
84   name <filename>data/css/default.css</filename>.</para>
85   <para>Since the path <code>/service/xmlrpc</code> has the XML-RPC filter
86   enabled, all the exposed methods of the object
87   <code>cherrypy.root.service.xmlrpc</code> will be treated as XML-RPC
88   methods.</para>
89   <para>The root entry, defined as <code>global</code>, is also responsible
90   for defining the server settings such as the port, the protocol version to
91   use by default, the number of threads to start with the server, etc.</para>
92   <para>All values in the configuration file must be valid Python values.
93   Strings must be quoted, booleans must be True or False, etc.</para>
94   <para>The <code>server.environment</code> entry controls how CherryPy should
95   run. Three values are legal:</para>
96   <itemizedlist>
97     <listitem>development <itemizedlist>
98         <listitem>logDebugInfoFilter is enabled by default</listitem>
99         <listitem>HTTPErrors (and therefore the default _cpOnError) display
100         tracebacks in the browser if errors occur</listitem>
101         <listitem>autoreload is enabled by default</listitem>
102       </itemizedlist></listitem>
103     <listitem>production <itemizedlist>
104         <listitem>logDebugInfoFilter is disabled by default</listitem>
105         <listitem>
106           <para>tracebacks are logged, but are not displayed in the
107           browser</para>
108         </listitem>
109         <listitem>autoreload is disabled by default</listitem>
110       </itemizedlist></listitem>
111     <listitem>staging (same as production for the moment)</listitem>
112   </itemizedlist>
113 </section>
Note: See TracBrowser for help on using the browser.

Hosted by WebFaction

Log in as guest/cpguest to create tickets