[Twisted-web] Hello introductions to me and one of my pet projects

David J W twistedwebmailinglist at ominian.net
Sun Oct 2 16:49:36 EDT 2011

    I've been using Twisted on and off now for about four years, mostly for
personal projects and some R&D work for a few startups.  I've been a
semi-professional Python programmer for four years as well, unfortunately it
only makes up about 15-20% of my annual income.  That said for Python web
development I was rather fond of Pylons and then moved from it to CherryPy.
 With those two frameworks influencing me, I wanted a similar interface for
Twisted.Web and after a lot of trial and error I've got an alpha version
proof of concept that is simply called txWeb.

Very briefly using an example from JCalderone's wonderful collection of

Instead of doing

from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.internet import reactor

class FormPage(Resource):
       def render_GET(self, request)
            return '<html><body><form method="POST"><input name="the-field"
type="text" /></form></body></html>'

       def render_POST(self, request):
             return '<html><body>You submitted: %s</body></html>' %

root = Resource()
root.putChild("form", FormPage() )
factory = Site(root)
reactor.listenTCP(8880, factory)

the alternative would be:

from txweb.core import Site
#from twisted.web.resource import Resource
from twisted.internet import reactor
import cgi

class Root(object):

    def form(self, request):
        return '<html><body><form action="/process" method="POST"><input
name="the-field" type="text" /></form></body></html>'
    form.exposed = True

    index = form

    def process(self, request):
        return '<html><body>You submitted: %s</body></html>' %
    process.exposed = True

reactor.listenTCP(8880, Site(Root()))

A cleaner version of the example above is available @

My goals with txWeb isn't to replace the twisted.web Resource mechanism but
instead provide an alternative that friendlier towards those with experience
with Pylons/CherryPy/Django while avoiding duplicating anything that
twisted.web provides ( ex. File resources can be class attributes )

That all said, any critique's or constructive input is very much welcome.
So far I know the unit-tests need to be cleaned up, inside the routing
routeRequest method the wrapper OneTimeResource is created, used, and thrown
away which is somewhat wasteful as its a mostly stateless object.  But I'm
not sure if I'm missing something big that could make txWeb unviable for
production use without some sort of major refactoring.

    David W.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20111002/4a12c692/attachment.htm 

More information about the Twisted-web mailing list