V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
danzzzz
V2EX  ›  Python

请问 flask_restful 如何在路由里面设置参数使其能够获取列表参数呢?

  •  
  •   danzzzz · 2018-10-27 00:41:25 +08:00 · 3471 次点击
    这是一个创建于 1999 天前的主题,其中的信息可能已经有所发展或是发生改变。

    api.add_resource(Todo,'/v1_todo/<id>'),比方说这样只能获取单个参数,但要怎么样才能获取从前端传过来的列表参数呢?最近刚接触 flask,还有很多不熟悉的地方,请多多包涵,先谢谢各位大大的解答了。</id>

    5 条回复    2018-10-31 00:35:52 +08:00
    mrchi
        1
    mrchi  
       2018-10-27 10:30:51 +08:00
    在 URL 里传列表?
    ltoddy
        2
    ltoddy  
       2018-10-27 11:02:03 +08:00
    from flask import request

    在 request 里面.
    gnozix
        3
    gnozix  
       2018-10-27 13:51:19 +08:00
    parser = RequestParser()
    parser.add_argument("id", location="json", action="append")

    req = parser.parse_args(strict=True)
    id_ = req.get("id")
    Mrkon
        4
    Mrkon  
       2018-10-29 16:50:30 +08:00
    楼主的意思是传表单, 3L 正解, 以下是官方文档的示例,楼主要多看官方文档哦

    from flask_restful import reqparse

    parser = reqparse.RequestParser()
    parser.add_argument('rate', type=int, help='Rate to charge for this resource')
    args = parser.parse_args()
    rate = args['rate']
    IceCola1
        5
    IceCola1  
       2018-10-31 00:35:52 +08:00
    from flask import request
    requst.json.get()
    别用 flask_restful 接收 List,有坑
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1014 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 20:08 · PVG 04:08 · LAX 13:08 · JFK 16:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.