1

私は tornado フレームワークを初めて使用します。URL 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 に答える