How to handle the dict of parms in tornado?

拟墨画扇 提交于 2019-12-20 04:57:15

问题


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. Please see the below code,

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),
])

My question is how to write the regular expression url ?


回答1:


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),
])


来源:https://stackoverflow.com/questions/18458392/how-to-handle-the-dict-of-parms-in-tornado

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!