Skip to content

Instantly share code, notes, and snippets.

@devdave
Created October 2, 2011 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdave/1257921 to your computer and use it in GitHub Desktop.
Save devdave/1257921 to your computer and use it in GitHub Desktop.
Reference twisted web example from Jcalderone's tutorials to using txWeb
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>' % (cgi.escape(request.args["the-field"][0]),)
process.exposed = True
reactor.listenTCP(8880, Site(Root()))
reactor.run()
from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.internet import reactor
import cgi
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>' % (cgi.escape(request.args["the-field"][0]),)
root = Resource()
root.putChild("form", FormPage() )
factory = Site(root)
reactor.listenTCP(8880, factory)
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment