NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

tut05_derived_objects.py (1328B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\lib\cherrypy\tutorial\tut05_derived_objects.py
      2 import cherrypy
      3 
      4 class Page:
      5     title = 'Untitled Page'
      6 
      7     def header(self):
      8         return '\n            <html>\n            <head>\n                <title>%s</title>\n            <head>\n            <body>\n            <h2>%s</h2>\n        ' % (self.title, self.title)
      9 
     10     def footer(self):
     11         return '\n            </body>\n            </html>\n        '
     12 
     13 
     14 class HomePage(Page):
     15     title = 'Tutorial 5'
     16 
     17     def __init__(self):
     18         self.another = AnotherPage()
     19 
     20     def index(self):
     21         return self.header() + '\n            <p>\n            Isn\'t this exciting? There\'s\n            <a href="./another/">another page</a>, too!\n            </p>\n        ' + self.footer()
     22 
     23     index.exposed = True
     24 
     25 
     26 class AnotherPage(Page):
     27     title = 'Another Page'
     28 
     29     def index(self):
     30         return self.header() + '\n            <p>\n            And this is the amazing second page!\n            </p>\n        ' + self.footer()
     31 
     32     index.exposed = True
     33 
     34 
     35 import os.path
     36 tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf')
     37 if __name__ == '__main__':
     38     cherrypy.quickstart(HomePage(), config=tutconf)
     39 else:
     40     cherrypy.tree.mount(HomePage(), config=tutconf)