我是龙卷风框架的新手,当我打开URL http://www.sample.com/index.html?roomid=1&presenterid=2时,tornado.web.RequestHandler需要处理参数的字典。请看下面的代码,
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?
最佳答案
查询字符串参数不作为关键字参数传递。使用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),
])
关于python - 如何处理 Tornado 中的Parms指令?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18458392/