2 gavinloveesther gavinloveesther 于 2014.09.23 14:29 提问

tornado web.py 重写tornado.web.RequestHandler 的构造函数

我想在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)

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!