How to handle the dict of parms in tornado?

前端 未结 1 936
囚心锁ツ
囚心锁ツ 2021-01-23 21:58

I am new to tornado framework.When I open the url http://www.sample.com/index.html?roomid=1&presenterid=2 the tornado.web.RequestHandler need to handle the dict of parms. Pl

1条回答
  •  囚心锁ツ
    2021-01-23 22:36

    Query string parameters are not passed as keyword arguments. Use 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),
    ])
    

    0 讨论(0)
提交回复
热议问题