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

tut04_complex_site.py (2062B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\lib\cherrypy\tutorial\tut04_complex_site.py
      2 import cherrypy
      3 
      4 class HomePage:
      5 
      6     def index(self):
      7         return '\n            <p>Hi, this is the home page! Check out the other\n            fun stuff on this site:</p>\n            \n            <ul>\n                <li><a href="/joke/">A silly joke</a></li>\n                <li><a href="/links/">Useful links</a></li>\n            </ul>'
      8 
      9     index.exposed = True
     10 
     11 
     12 class JokePage:
     13 
     14     def index(self):
     15         return '\n            <p>"In Python, how do you create a string of random\n            characters?" -- "Read a Perl file!"</p>\n            <p>[<a href="../">Return</a>]</p>'
     16 
     17     index.exposed = True
     18 
     19 
     20 class LinksPage:
     21 
     22     def __init__(self):
     23         self.extra = ExtraLinksPage()
     24 
     25     def index(self):
     26         return '\n            <p>Here are some useful links:</p>\n            \n            <ul>\n                <li><a href="http://www.cherrypy.org">The CherryPy Homepage</a></li>\n                <li><a href="http://www.python.org">The Python Homepage</a></li>\n            </ul>\n            \n            <p>You can check out some extra useful\n            links <a href="./extra/">here</a>.</p>\n            \n            <p>[<a href="../">Return</a>]</p>\n        '
     27 
     28     index.exposed = True
     29 
     30 
     31 class ExtraLinksPage:
     32 
     33     def index(self):
     34         return '\n            <p>Here are some extra useful links:</p>\n            \n            <ul>\n                <li><a href="http://del.icio.us">del.icio.us</a></li>\n                <li><a href="http://www.mornography.de">Hendrik\'s weblog</a></li>\n            </ul>\n            \n            <p>[<a href="../">Return to links page</a>]</p>'
     35 
     36     index.exposed = True
     37 
     38 
     39 root = HomePage()
     40 root.joke = JokePage()
     41 root.links = LinksPage()
     42 import os.path
     43 tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf')
     44 if __name__ == '__main__':
     45     cherrypy.quickstart(root, config=tutconf)
     46 else:
     47     cherrypy.tree.mount(root, config=tutconf)