Updates Journal
Feb 5, 2009
- Dealing with deciding on HTTP TwistedWeb, but received error starting it up.
There are high-level Web Application frameworks using Twisted, such as Zope and Divmod Nevow. These are good for complete sites with databases. I am looking for a simple HTTP server for regular HTTP files, so the Twisted people recommended using TwistedWeb. TwistedWeb2 is being implemented back into TwistedWeb1, so I'll stick with the original TwistedWeb.
- Notes below taken from TwistedWeb documentation)
- There are two ways to run a site using TwistedWeb, command line or writing a program:
- Site objects serve as the glue between a port to listen for HTTP requests on, and a root Resource object.
- When using twistd -n web --path /foo/bar/baz, a Site object is created with a root Resource that serves files out of the given path.
- You can also create a Site instance by hand, passing it a Resource object which will serve as the root of the site:
from twisted.web import server, resource
from twisted.internet import reactor
class Simple(resource.Resource):
isLeaf = True
def render_GET(self, request):
return "<html>Hello, world!</html>"
site = server.Site(Simple())
reactor.listenTCP(8080, site)
reactor.run()