当前位置:网站首页>Different styles of Flask-restful
Different styles of Flask-restful
2022-08-09 08:03:00 【scwMason】
Reference Articlehttp://www.pythondoc.com/Flask-RESTful/quickstart.html
http://www.pythondoc.com/Flask-RESTful/reqparse.html
To summarize this module:
1. You can use add_resource to process urls in batches, no need to add before each [email protected]
2. The most important function of flask-restful is the parameter parsing of requests that carry data in post, which can be roughly understood as:
First you need to create the object:
parser = reqparse.RequestParser()parser.add_argument('task', type=str)
Then parsed parameters are stored in args
args = parser.parse_args()
Parameter location
parser.add_argument('name', type=int, location='form')# Look only in the querystringparser.add_argument('PageSize', type=int, location='args')# From the request headersparser.add_argument('User-Agent', type=str, location='headers')# From http cookiesparser.add_argument('session_id', type=str, location='cookies')# From file uploadsparser.add_argument('picture', type=werkzeug.datastructures.FileStorage, location='files')
Change name
If you don't want to get the parameter value by parameter name, you can:
parser.add_argument('name', type=str, dest='public_name')args = parser.parse_args()args['public_name']
Required parameters
To require an argument by value, just add required=True
to call add_argument()
.
parser.add_argument('name', type=str, required=True,help="Name cannot be blank!")
Cannot get parameters
If we set "session_id" as a cookie, our args will not be available:
parser.add_argument('session_id',type=str,location="cookies")args=parser.parse_args()
Send request:
curl http://localhost:5000/todos -d "task=soming new" -d "name=mason" -d "session_id=hello word" -X POST -v
print args
Multiple values passed
parser.add_argument('session_id',type=str,location="cookies",action="append")
At this time, when passing the value of session_id, you need: -d "session_id=123" -d "session_id=456" like this
These are the points I think are more important in the article, and I summarize them by myself
边栏推荐
猜你喜欢
C language: adjust the order of odd and even numbers
LVM与磁盘配额
世界顶尖3D Web端渲染引擎:HOOPS Communicator技术介绍(一)
The story of the disappearing WLAN of Windows 10 computers
LeetCode: 876. The middle node of the linked list —— simple
Shell--常用小工具(sort、uniq、tr、cut)
Oracle 限制时将空值排除
Shell之函数与数组
Shell编程之正则表达式
.net(五) 业务层实现
随机推荐
.net(三) 项目结构
EXCEL使用函数联调(find,mid,vlookup,xlookup)
Collection 接口 & List 接口
(三)、时间序列预测
C language: reverse character order
pragma comment的使用(转载)重新排版
Cookie和Session详解
C语言:汽水瓶详解
web基本概念
test process
2019 Nanchang Internet Competition Question C, Hello 2019
MySql作业练习题
SSM integration development case
弹性盒样式、移动端、VW适配、响应式布局
oracle存储过程问题解答
可能导致Loadrunner检查点中savecount为0的分析
IO字节流读取文本中文乱码
[STL]list
练习电影卡片、过渡、动画、变形、旋转,练习时钟、立方体、缩放
(四)BP神经网络预测(上)