python 使用get_argument获取url query参数
作者:lqh 时间:2023-02-12 03:52:18
python 使用get_argument获取url query参数
ornado的每个请求处理程序,我们叫做handler,handler里可以自定义自己的处理程序,其实也就是重写方法,如post,get,get_current_user,send_error等等,这里我们只讲get和post的自定义。
我们都知道,在Tornado里,获得用户的输入,都是一个get_argument搞定,似乎很顺理成章:
def post(self):
nowamagic = self.get_argument('nowamagic')
self.write( nowamagic )
先介绍一点基本知识。我们来看看这么一个URL:http://www.nowamagic.net/academy/detail/13321002?page=1#comment
>>> import urlparse
>>> urlparse.urlparse('http://www.nowamagic.net/academy/detail/13321002?page=1#comment')
ParseResult(scheme='http', netloc='www.nowamagic.net', path='/academy/detail/13321002', params='', query='page=1', fragment='comment')
url由scheme(协议),netloc(主机),path(路径),params(最后路径的参数),query(查询字段),fragment(锚)组成。
下面我们要获取URL里的GET参数,也就是获取url query中的参数,怎么办呢?
对于单一的值,在get和post中调用self.get_argument("name", "default")。
对于多选的值,调用self.get_arguments("name")即可。
get_argument方法可以设置默认值,也可以设置是否删除两端的空格。
源码声明如下:
get_argument(self, name, default=_ARG_DEFAULT, strip=True)
get_arguments(self, name, strip=True)
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
来源:http://www.nowamagic.net/academy/detail/1332605
标签:get,argument,url,query
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
myFocus 一个KindEditor的焦点图插件
2023-11-09 03:56:09
![](https://img.aspxhome.com/file/2023/3/71293_0s.jpg)
Go语言中的匿名结构体用法实例
2023-07-07 11:10:21
Pytorch使用MNIST数据集实现基础GAN和DCGAN详解
2021-11-17 02:14:33
![](https://img.aspxhome.com/file/2023/3/72183_0s.jpg)
浅谈哪个Python库才最适合做数据可视化
2022-12-05 00:34:58
![](https://img.aspxhome.com/file/2023/1/97351_0s.png)
Django实现分页功能
2023-04-04 11:00:56
![](https://img.aspxhome.com/file/2023/4/72104_0s.png)
交互设计的方法
2010-08-18 12:32:00
![](https://img.aspxhome.com/file/UploadPic/20108/18/01-52s.jpg)
浅谈关于axios和session的一些事
2024-05-11 09:49:33
![](https://img.aspxhome.com/file/2023/6/125856_0s.png)
vue3中使用ref和emit来减少props的使用示例详解
2024-04-27 16:02:02
![](https://img.aspxhome.com/file/2023/5/133045_0s.png)
ADO的错误码对应的含义
2007-10-22 17:31:00
opencv实现图像平移效果
2022-09-30 00:22:06
![](https://img.aspxhome.com/file/2023/0/112470_0s.jpg)
GO语言操作Elasticsearch示例分享
2023-09-03 03:38:00
python实现超市商品销售管理系统
2021-01-06 22:18:14
![](https://img.aspxhome.com/file/2023/9/93529_0s.jpg)
如何利用python给图片添加半透明水印
2022-08-16 09:34:28
![](https://img.aspxhome.com/file/2023/3/105193_0s.png)
ORACLE数据库查看执行计划的方法
2012-06-06 20:15:52
SQL 查询连续登录的用户情况
2024-01-29 01:27:18
![](https://img.aspxhome.com/file/2023/0/104110_0s.png)
JavaScript实现省市联动过程中bug的解决方法
2024-04-19 10:46:05
泛泛而谈界面中的斑马纹设计
2010-07-15 12:59:00
![](https://img.aspxhome.com/file/UploadPic/20107/15/bm-001-76s.jpg)
Python中ini配置文件读写的实现
2021-03-15 09:52:01
python如何实现质数求和
2023-03-02 20:17:24
python 中的int()函数怎么用
2021-05-21 17:52:41