推荐学习书目
› 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
ray1888
V2EX  ›  Python

Django 如何优雅的接收表单参数

  •  
  •   ray1888 ·
    ray1888 · May 15, 2018 · 3328 views
    This topic created in 3067 days ago, the information mentioned may be changed or developed.

    现在遇到一个问题,在 Django 中有什么好的方法接收处理一些未知数量的参数呢(就是可能假设一个实体,可能有多个属性,但是我可能不知道传过来有多少个),除了 request.POST.get($attr,'')这种方法以外,还有什么其他更简单的方法吗?

    4 replies  •  2018-05-16 12:45:32 +08:00
    ray1888
        1
    ray1888  
    OP
       May 15, 2018
    之前还试过一种方法是,用一个变量把 request.POST 整个参数接收下来,然后遍历属性,使用正则来进行匹配,然后放到数组中,感觉还是不够优雅
    tempdban
        2
    tempdban  
       May 15, 2018 via Android
    for k,v in request.POST.values():
    tempdban
        3
    tempdban  
       May 15, 2018 via Android
    for k,v in request.POST.items():
    wizardoz
        4
    wizardoz  
       May 16, 2018
    json 字段加 json schema
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5488 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 03:49 · PVG 11:49 · LAX 20:49 · JFK 23:49
    ♥ Do have faith in what you're doing.