dhana
dhana

Reputation: 6525

How to handle the dict of parms in tornado?

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 ?

Upvotes: 1

Views: 455

Answers (1)

falsetru
falsetru

Reputation: 369364

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

Upvotes: 2

Related Questions