from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.internet import reactor
from twisted.web.resource import NoResource
from calendar import calendar
class Calendar(Resource):
def getChild(self, path, request):
try:
year = int(path)
except ValueError:
return NoResource()
else:
return YearPage(year)
class YearPage(Resource):
def __init__(self, year):
Resource.__init__(self)
self.year = year
4. Other Request Bodies
http://twistedmatrix.com/documents/current/web/howto/web-in-60/other-request-bodies.html
Not the args attribute, but the content attribute.
We fetch the request body directly from request.content.
class FormPage(Resource):
def render_POST(self, request):
return """
<html>
<body>You submitted: %s</body>
</html>
""" % (cgi.escape(request.content.read()))
It works. but I saw another Error Message:
twisted/test/raiser.c:4:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
Solution:
> sudo apt-get install python-dev
For the permission issue, I use sudo to install that.
Successfully install twisted.
I try to use print twisted.version to verify the installation. But it does not work. But I can run all the twisted classes in python.
Oh, I need to import twisted first.
>>> import twisted
>>> print twisted.version
[twisted, version 15.4.0]