如何处理龙卷风中的parms dict? [英] How to handle the dict of parms in tornado?

查看:37
本文介绍了如何处理龙卷风中的parms dict?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 tornado 框架的新手.当我打开 url http://www.sample.com/index.html?roomid=1&presenterid=2 tornado.web.RequestHandler 需要处理 parms 的字典.请看下面的代码,

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

我的问题是正则表达式url怎么写?

My question is how to write the regular expression url ?

推荐答案

查询字符串参数不作为关键字参数传递.使用 getargument:

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

这篇关于如何处理龙卷风中的parms dict?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆