Hi, I tried this example class ColorPage(resource.Resource): def __init__(self, color): self.color = color def render(self, request): return """ <html> <head> <title>Color: %s</title> <DEFANGED_link type='text/css' href='/css/styles.css' rel='Stylesheet' /> </head> <body DEFANGED_STYLE='background-color: #%s'> <h1>This is #%s.</h1> <p DEFANGED_STYLE='background-color: white'> <a href='/colors/'>Back</a> </p> </body> </html> """ % (self.color, self.color, self.color) class ColorRoot(resource.Resource): def __init__(self): resource.Resource.__init__(self) self.requestedColors = [] self.putChild('', ColorIndexPage(self.requestedColors)) def render(self, request): # redirect /colors -> /colors/ request.redirect(request.path + '/') return "Please use /colors/ instead." def getChild(self, path, request): if path not in self.requestedColors: self.requestedColors.append(path) return ColorPage(path) class ColorIndexPage(resource.Resource): def __init__(self, requestedColorsList): resource.Resource.__init__(self) self.requestedColors = requestedColorsList def render(self, request): request.write(""" <html> <head> <title>Colors</title> <DEFANGED_link type='text/css' href='/css/styles.css' rel='Stylesheet' /> </head> <body> <h1>Colors</h1> To see a color, enter a url like <a href='ff0000'>/colors/ff0000</a>. <br /> Colors viewed so far: <ul>""") for color in self.requestedColors: request.write( "<li><a href='%s' DEFANGED_STYLE='color: #%s'>%s</a></li>" % ( color, color, color)) request.write(""" </ul> </body> </html> """) return "" class HomePage(resource.Resource): def render(self, request): return """ <html> <head> <title>Colors</title> <DEFANGED_link type='text/css' href='/css/styles.css' rel='Stylesheet' /> </head> <body> <h1>Colors Demo</h1> What's here: <ul> <li><a href='/colors'>Color viewer</a></li> </ul> </body> </html> """ if __name__ == "__main__": from twisted.internet import reactor root = resource.Resource() root.putChild('', HomePage()) root.putChild('colors', ColorRoot()) styles = resource.Resource() styles.putChild('styles.css', static.File('styles.css')) root.putChild('css', styles) site = server.Site(root) reactor.listenTCP(8000, site) reactor.run() with CSS code in external file styles.css, the code is like this body { font-family: Georgia, Times, serif; font-size: 11pt; } h1 { margin: 10px 0; padding: 5px; background-color: black; color: white; } a{ font-family: monospace; } p{ padding: 10px; } But, there is no results. Any pointer what I am doing wrong, I am using MAC OS leopard. Thanks dowell
participants (1)
-
arun chhetri