Tornado - Get variable from URL -
i have 2 handlers. in first 1 (foohandler) show form, in method, , value of field, post method. once obtained value wanna pass handler through uri. barhandler catch , able make query.
class foohandler(tornado.web.requesthandler): def get(self): self.render("templates/fooform.html") def post(self): var1 = self.get_argument('var1') #number self.redirect('/query/{}'.format(var1)) class barhandler(tornado.web.requesthandler): def get(self, var1): q = query.... def main(): io_loop = tornado.ioloop.ioloop.instance() connect("test", host="localhost", port=27017, io_loop=io_loop) app = tornado.web.application( [ (r"/", foohandler), (r"/query/\d+", barhandler) ], debug = true, ) app.listen(8888) tornado.ioloop.ioloop.current().start() if __name__ == "__main__": main()
i error:
traceback (most recent call last): file "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 1443, in _execute result = method(*self.path_args, **self.path_kwargs) typeerror: get() takes 2 arguments (1 given)
i'm not sure how pass var1 foohandler , catch in barhandler. suggestion?
from documentation:
any groups in regex passed in handler’s get/post/etc methods arguments.
you need use group in regex path, if want pass part of path handler.
you should define path as:
(r"/query/(\d+)", barhandler)
Comments
Post a Comment