2 Tutorial - Object inheritance
4 You are free to derive your request handler classes from any base
5 class you wish. In most real-world applications, you will probably
6 want to create a central base class used for all your pages, which takes
7 care of things like printing a common page header and footer.
14 # Store the page title in a class attribute
15 title
= 'Untitled Page'
25 ''' % (self
.title
, self
.title
)
33 # Note that header and footer don't get their exposed attributes
34 # set to True. This isn't necessary since the user isn't supposed
35 # to call header or footer directly; instead, we'll call them from
36 # within the actually exposed handler methods defined in this
41 # Different title for this page
46 self
.another
= AnotherPage()
49 # Note that we call the header and footer methods inherited
50 # from the Page class!
51 return self
.header() + '''
53 Isn't this exciting? There's
54 <a href="./another/">another page</a>, too!
60 class AnotherPage(Page
):
61 title
= 'Another Page'
64 return self
.header() + '''
66 And this is the amazing second page!
73 tutconf
= os
.path
.join(os
.path
.dirname(__file__
), 'tutorial.conf')
75 if __name__
== '__main__':
76 # CherryPy always starts with app.root when trying to map request URIs
77 # to objects, so we need to mount a request handler root. A request
78 # to '/' will be mapped to HelloWorld().index().
79 cherrypy
.quickstart(HomePage(), config
=tutconf
)
81 # This branch is for the test suite; you can ignore it.
82 cherrypy
.tree
.mount(HomePage(), config
=tutconf
)