当前位置:网站首页>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语言:打印菱形
- 【Rust指南】快速入门|开发环境|hello world
- Data storage implementation of SDRAM and read and write operations on its data
- Selenium测试案例一步步学之(2)Selenium自动测试脚本模块化(下)
- 动态设置img标签图片失效问题
- 9.进程和计划任务管理(1)
- OpenHarmony轻智能产品开发直播笔记
- Four departments including the Ministry of Industry and Information Technology promote green smart home products to the countryside
- Anaconda use proxy
- pip3 source change to improve speed
猜你喜欢
随机推荐
.net(二) 配置数据库
动态设置img标签图片失效问题
(三)、时间序列预测
The Martian - Simple Math Problems
One-click login server script
Buns make up the number----Euclide+dp
Kotlin Coroutines - Exception Handling
VRRP原理及配置
Solidworks 2022 Inspection新增功能:光学字符识别、可自定义的检查报告
pc端ncnn搭建与测试
研发分享:机器学习卡片的使用
C language: adjust the order of odd and even numbers
.net(三) 项目结构
C#基础学习
图像处理(一)图像基础
泛型和lambda表达式
Forest Program DFS + tanjar cactus
Oracle 限制时将空值排除
世界顶尖3D Web端渲染引擎:HOOPS Communicator技术介绍(一)
yolov5 detects the number of labels in the dataset