Created
June 28, 2009 08:50
-
-
Save FND/137223 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Nevow & Stan tutorial (EuroPython 2009) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | |
| <html lang="en"> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
| <title>Goodbye</title> | |
| </head> | |
| <body> | |
| <h1>Goodbye</h1> | |
| <p>See you later.</p> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | |
| <html lang="en"> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
| <title>Hello</title> | |
| </head> | |
| <body> | |
| <h1>Hello</h1> | |
| <p>Welcome!</p> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env sh | |
| twistd -noy server.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from time import time | |
| from twisted.application import internet, service | |
| from nevow import appserver, loaders, tags, static, rend | |
| class InfoTree(rend.Page): | |
| addSlash = True | |
| children = { | |
| "help": static.File("./htdocs/help.html") | |
| } | |
| def locateChild(self, ctx, segments): | |
| r = self.children.get(segments[0], None) | |
| if r is not None: | |
| return r, segments[1:] | |
| class TimeDisplay(rend.Page): | |
| docFactory = loaders.xmlfile("./templates/time.html") | |
| def render_now(self, ctx, data): | |
| return ctx.tag[unicode(time())] | |
| class TopLevel(rend.Page): | |
| addSlash = True | |
| docFactory = loaders.stan(tags.html["Ths is the top-level resource."]) | |
| children = { | |
| "info": InfoTree(), | |
| "time": TimeDisplay(), | |
| "hello": static.File("./htdocs/hello.html"), | |
| "goodbye": static.File("./htdocs/goodbye.html") | |
| } | |
| def locateChild(self, ctx, segments): | |
| if segments[0] == "": | |
| return self, [] | |
| r = self.children.get(segments[0], None) | |
| if r is not None: | |
| return r, segments[1:] | |
| if __name__ == "__builtin__": | |
| # create application and give it a name | |
| application = service.Application('helloworld') | |
| # create a server and connect it to an object that will resolve URLs and | |
| # serve up web pages (or other resources) | |
| site = appserver.NevowSite(TopLevel()) | |
| # create a webserver instance, binding it to port and the site object | |
| webServer = internet.TCPServer(8090, site) | |
| # bind the application to the webserver | |
| webServer.setServiceParent(application) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
| <html xmlns="http://www.w3.org/1999/xhtml" | |
| xmlns:n="http://nevow.com/ns/nevow/0.1"> | |
| <head> | |
| <meta content="text/html; charset=utf-8" /> | |
| <title>The current time</title> | |
| </head> | |
| <body> | |
| <h1>Time</h1> | |
| <p> | |
| The time is now <b n:render="now"></b>. | |
| </p> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment