1 """
2 Tutorial - Multiple objects
3
4 This tutorial shows you how to create a site structure through multiple
5 possibly nested request handler objects.
6 """
7
8 import cherrypy
9
10
12
14 return '''
15 <p>Hi, this is the home page! Check out the other
16 fun stuff on this site:</p>
17
18 <ul>
19 <li><a href="/joke/">A silly joke</a></li>
20 <li><a href="/links/">Useful links</a></li>
21 </ul>'''
22 index.exposed = True
23
24
26
28 return '''
29 <p>"In Python, how do you create a string of random
30 characters?" -- "Read a Perl file!"</p>
31 <p>[<a href="../">Return</a>]</p>'''
32 index.exposed = True
33
34
36
38
39
40
41 self.extra = ExtraLinksPage()
42
44
45
46
47
48 return '''
49 <p>Here are some useful links:</p>
50
51 <ul>
52 <li>
53 <a href="http://www.cherrypy.org">The CherryPy Homepage</a>
54 </li>
55 <li>
56 <a href="http://www.python.org">The Python Homepage</a>
57 </li>
58 </ul>
59
60 <p>You can check out some extra useful
61 links <a href="./extra/">here</a>.</p>
62
63 <p>[<a href="../">Return</a>]</p>
64 '''
65 index.exposed = True
66
67
69
71
72 return '''
73 <p>Here are some extra useful links:</p>
74
75 <ul>
76 <li><a href="http://del.icio.us">del.icio.us</a></li>
77 <li><a href="http://www.cherrypy.org">CherryPy</a></li>
78 </ul>
79
80 <p>[<a href="../">Return to links page</a>]</p>'''
81 index.exposed = True
82
83
84
85 root = HomePage()
86 root.joke = JokePage()
87 root.links = LinksPage()
88
89
90
91
92
93
94
95 import os.path
96 tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf')
97
98 if __name__ == '__main__':
99
100
101
102 cherrypy.quickstart(root, config=tutconf)
103 else:
104
105 cherrypy.tree.mount(root, config=tutconf)
106