前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >flask webargs传参解析(flask 103)

flask webargs传参解析(flask 103)

作者头像
用户5760343
发布2019-08-20 11:04:09
1.1K0
发布2019-08-20 11:04:09
举报
文章被收录于专栏:sktjsktj

https://webargs.readthedocs.io/en/latest/

https://webargs.readthedocs.io/en/latest/quickstart.html#

from flask import Flask from webargs import fields from webargs.flaskparser import use_args

app = Flask(name)

hello_args = {"name": fields.Str(required=True)}

@app.route("/") @use_args(hello_args) def index(args): return "Hello " + args["name"]

if name == "main": app.run()

curl http://localhost:5000/?name='World'

Hello World

Webargs will automatically parse:

Query Parameters

$ curl http://localhost:5000/?name='Freddie' Hello Freddie Form Data

$ curl -d 'name=Brian' http://localhost:5000/ Hello Brian JSON Data

$ curl -X POST -H "Content-Type: application/json" -d '{"name":"Roger"}' http://localhost:5000/ Hello Roger

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.08.14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • https://webargs.readthedocs.io/en/latest/
  • https://webargs.readthedocs.io/en/latest/quickstart.html#
  • curl http://localhost:5000/?name='World'
  • Hello World
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档