推荐学习书目
› 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 · Oct 27, 2018 · 4694 views
    This topic created in 2895 days ago, the information mentioned may be changed or developed.

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

    5 replies  •  2018-10-31 00:35:52 +08:00
    mrchi
        1
    mrchi  
       Oct 27, 2018
    在 URL 里传列表?
    ltoddy
        2
    ltoddy  
       Oct 27, 2018
    from flask import request

    在 request 里面.
    gnozix
        3
    gnozix  
       Oct 27, 2018
    parser = RequestParser()
    parser.add_argument("id", location="json", action="append")

    req = parser.parse_args(strict=True)
    id_ = req.get("id")
    Mrkon
        4
    Mrkon  
       Oct 29, 2018
    楼主的意思是传表单, 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  
       Oct 31, 2018
    from flask import request
    requst.json.get()
    别用 flask_restful 接收 List,有坑
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   989 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 18:49 · PVG 02:49 · LAX 11:49 · JFK 14:49
    ♥ Do have faith in what you're doing.