[CPyUG] tornado有没有自带的处理某个请求字段不存在的机制?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[CPyUG] tornado有没有自带的处理某个请求字段不存在的机制?

viders
比如tornado中计划要接受一个参数noexists,用下面的语句接受的:
noexists = self.request.arguments.get('name')[0]
但是由于某些原因,浏览器并没有把这个字段发出,那么程序这时候就会挂掉,我目前的做法是:
        try:
            noexists = self.request.arguments.get('name')[0]
        except TypeError, message:
            print message
            noexists = None

感觉这个方法比较笨,不知道有没有好点的做法?

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [CPyUG] tornado有没有自带的处理某个请求字段不存在的机制?

Felinx Lee
 noexists = self.request.argument.get('name', None) 

2011/12/29 viders <[hidden email]>
比如tornado中计划要接受一个参数noexists,用下面的语句接受的:
noexists = self.request.arguments.get('name')[0]
但是由于某些原因,浏览器并没有把这个字段发出,那么程序这时候就会挂掉,我目前的做法是:
        try:
            noexists = self.request.arguments.get('name')[0]
        except TypeError, message:
            print message
            noexists = None

感觉这个方法比较笨,不知道有没有好点的做法?

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html



--
What can change the nature of a man?(Planescape Torment)
----------------------------------------------------------------------------------------
http://feilong.me            Felinx Lee's Blog (Chinese Only)
http://www.zhimaq.com IT Q&A (Chinese Only)
http://poweredsites.org  What powered your sites? PHP, Ruby or Python?

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [CPyUG] tornado有没有自带的处理某个请求字段不存在的机制?

Forrest Liu
这跟tornado不搭嘎,是python基础问题...
http://docs.python.org/library/stdtypes.html#dict.get 

2011/12/29 Felinx Lee <[hidden email]>
 noexists = self.request.argument.get('name', None) 


2011/12/29 viders <[hidden email]>
比如tornado中计划要接受一个参数noexists,用下面的语句接受的:
noexists = self.request.arguments.get('name')[0]
但是由于某些原因,浏览器并没有把这个字段发出,那么程序这时候就会挂掉,我目前的做法是:
        try:
            noexists = self.request.arguments.get('name')[0]
        except TypeError, message:
            print message
            noexists = None

感觉这个方法比较笨,不知道有没有好点的做法?

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html



--
What can change the nature of a man?(Planescape Torment)
----------------------------------------------------------------------------------------
http://feilong.me            Felinx Lee's Blog (Chinese Only)
http://www.zhimaq.com IT Q&A (Chinese Only)
http://poweredsites.org  What powered your sites? PHP, Ruby or Python?


--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html



--
 
Best regards,
Forrest Liu

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [CPyUG] tornado有没有自带的处理某个请求字段不存在的机制?

Felinx Lee
In reply to this post by Felinx Lee
补充下,也可以这样玩
noexists = self. get_argument('name', None)   

2011/12/29 Felinx Lee <[hidden email]>
 noexists = self.request.arguments.get('name', None) 


2011/12/29 viders <[hidden email]>
比如tornado中计划要接受一个参数noexists,用下面的语句接受的:
noexists = self.request.arguments.get('name')[0]
但是由于某些原因,浏览器并没有把这个字段发出,那么程序这时候就会挂掉,我目前的做法是:
        try:
            noexists = self.request.arguments.get('name')[0]
        except TypeError, message:
            print message
            noexists = None

感觉这个方法比较笨,不知道有没有好点的做法?

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html



--
What can change the nature of a man?(Planescape Torment)
----------------------------------------------------------------------------------------
http://feilong.me            Felinx Lee's Blog (Chinese Only)
http://www.zhimaq.com IT Q&A (Chinese Only)
http://poweredsites.org  What powered your sites? PHP, Ruby or Python?




--
What can change the nature of a man?(Planescape Torment)
----------------------------------------------------------------------------------------
http://feilong.me            Felinx Lee's Blog (Chinese Only)
http://www.zhimaq.com IT Q&A (Chinese Only)
http://poweredsites.org  What powered your sites? PHP, Ruby or Python?

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [CPyUG] tornado有没有自带的处理某个请求字段不存在的机制?

Forrest Liu
get_argument和get_arguments貌似才是tornado的标准参数获取方法

2011/12/29 Felinx Lee <[hidden email]>
补充下,也可以这样玩
noexists = self. get_argument('name', None)   

2011/12/29 Felinx Lee <[hidden email]>
 noexists = self.request.arguments.get('name', None) 


2011/12/29 viders <[hidden email]>
比如tornado中计划要接受一个参数noexists,用下面的语句接受的:
noexists = self.request.arguments.get('name')[0]
但是由于某些原因,浏览器并没有把这个字段发出,那么程序这时候就会挂掉,我目前的做法是:
        try:
            noexists = self.request.arguments.get('name')[0]
        except TypeError, message:
            print message
            noexists = None

感觉这个方法比较笨,不知道有没有好点的做法?

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html



--
What can change the nature of a man?(Planescape Torment)
----------------------------------------------------------------------------------------
http://feilong.me            Felinx Lee's Blog (Chinese Only)
http://www.zhimaq.com IT Q&A (Chinese Only)
http://poweredsites.org  What powered your sites? PHP, Ruby or Python?




--
What can change the nature of a man?(Planescape Torment)
----------------------------------------------------------------------------------------
http://feilong.me            Felinx Lee's Blog (Chinese Only)
http://www.zhimaq.com IT Q&A (Chinese Only)
http://poweredsites.org  What powered your sites? PHP, Ruby or Python?

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html



--
 
Best regards,
Forrest Liu

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [CPyUG] tornado有没有自带的处理某个请求字段不存在的机制?

peng yu-2
noexists = self.request.arguments.get('name')

在 2011年12月29日 下午4:59,Forrest Liu <[hidden email]>写道:
get_argument和get_arguments貌似才是tornado的标准参数获取方法

2011/12/29 Felinx Lee <[hidden email]>
补充下,也可以这样玩
noexists = self. get_argument('name', None)   

2011/12/29 Felinx Lee <[hidden email]>
 noexists = self.request.arguments.get('name', None) 


2011/12/29 viders <[hidden email]>
比如tornado中计划要接受一个参数noexists,用下面的语句接受的:
noexists = self.request.arguments.get('name')[0]
但是由于某些原因,浏览器并没有把这个字段发出,那么程序这时候就会挂掉,我目前的做法是:
        try:
            noexists = self.request.arguments.get('name')[0]
        except TypeError, message:
            print message
            noexists = None

感觉这个方法比较笨,不知道有没有好点的做法?

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html



--
What can change the nature of a man?(Planescape Torment)
----------------------------------------------------------------------------------------
http://feilong.me            Felinx Lee's Blog (Chinese Only)
http://www.zhimaq.com IT Q&A (Chinese Only)
http://poweredsites.org  What powered your sites? PHP, Ruby or Python?




--
What can change the nature of a man?(Planescape Torment)
----------------------------------------------------------------------------------------
http://feilong.me            Felinx Lee's Blog (Chinese Only)
http://www.zhimaq.com IT Q&A (Chinese Only)
http://poweredsites.org  What powered your sites? PHP, Ruby or Python?

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html



--
 
Best regards,
Forrest Liu

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: [hidden email]
退订: [hidden email] (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html
Loading...