On Sun, May 09, 2004 at 08:08:43AM -0400, pxlpluker wrote:
can anyone point out a good example of setting up a cgi capable twisted
web?
from twisted.web import twcgi, server
from twisted.application import internet, service
cgidir = twcgi.CGIDirectory('/var/www/cgi-bin') # Or wherever
site = server.Site(cgidir)
application = service.Application('cgi-demo')
sc = service.IServiceCollection(application)
i = internet.TCPServer(8080, site)
i.setServiceParent(sc)
if __name__ == '__main__':
from twisted.internet import reactor
sc.startService()
reactor.run()
sc.stopService()
This script can be run directly, or you can use Twisted's "twistd" utility
on it, which provides logging and daemonisation for you. (And if you use
twistd you don't need the if __name__ == '__main__' part.)
So, save this script as cgidemo.py and do:
python cgidemo.py
or:
twistd -noy cgidemo.py # See twistd docs for meanings of -n, -o and -y.
See
http://twistedmatrix.com/documents/c...ing-twistedweb for
more details, or ask on the twisted-web mailing list
(
http://twistedmatrix.com/cgi-bin/mai...o/twisted-web).
-Andrew.