我想在url路由中传递参数,但是不会重写tornado.web.RequestHandler的构造函数,求大神指点。
怎么就收路由里面 AppHandler 传递的“abc”
感恩!
coding: utf-8
import datetime, sys, SocketServer,time
import tornado.httpserver
import tornado.ioloop
from tornado.options import define, options
import tornado.web
import tornado.database
import tornado.escape
import urlparse
import urllib
import re
reload (sys)
sys.setdefaultencoding('utf-8')
class Application(tornado.web.Application):
def init(self):
handlers = [
(r"/abc", AppHandler("abc")),
]
settings = dict(
debug = False,
)
tornado.web.Application.__init__(self, handlers, **settings)
class AppHandler(tornado.web.RequestHandler):
def init(self, *args, **kwargs):
tornado.web.RequestHandler.__init__( self, *args, **kwargs )
self.action=${接收“abc”}
def post(self):
try:
self.today = datetime.datetime.today()
self.did = self.get_argument("did", default = "")
except:
pass
self.set_status(204)
self.finish()
def get(self):
try:
pass
except Exception, e:
raise
else:
pass
finally:
pass
def main(argv):
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(Application(), xheaders=True)
http_server.listen(int(argv[1]))
tornado.ioloop.IOLoop.instance().start()
print "start listening..."
if name == "__main__":
main(sys.argv)