1

我是龙卷风框架的新手。当我打开网址http://www.sample.com/index.html?roomid=1&presenterid=2时,tornado.web.RequestHandler 需要处理 parms 的字典。请看下面的代码,

class MainHandler(tornado.web.RequestHandler):
    def get(self, **kwrgs):
        self.write('I got the output ya')

application = tornado.web.Application([
    (r"/index.html?roomid=([0-9])&presenterid=([0-9])", MainHandler),
])

我的问题是如何编写正则表达式 url ?

4

1 回答 1

2

查询字符串参数不作为关键字参数传递。使用getargument

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        roomid = self.get_argument('roomid', None)
        presenterid = self.get_argument('presenterid', None)
        if roomid is None or presenterid is None:
            self.redirect('/') # root url
            return
        self.write('I got the output ya {} {}'.format(roomid, presenterid))

application = tornado.web.Application([
    (r"/index\.html", MainHandler),
])
于 2013-08-27T06:33:00.500 回答