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
ray1888
V2EX  ›  Python

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

  •  
  •   ray1888 ·
    ray1888 · 2018-05-15 19:34:01 +08:00 · 2727 次点击
    这是一个创建于 2165 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    4 条回复    2018-05-16 12:45:32 +08:00
    ray1888
        1
    ray1888  
    OP
       2018-05-15 19:47:43 +08:00
    之前还试过一种方法是,用一个变量把 request.POST 整个参数接收下来,然后遍历属性,使用正则来进行匹配,然后放到数组中,感觉还是不够优雅
    tempdban
        2
    tempdban  
       2018-05-15 20:51:51 +08:00 via Android
    for k,v in request.POST.values():
    tempdban
        3
    tempdban  
       2018-05-15 20:52:30 +08:00 via Android
    for k,v in request.POST.items():
    wizardoz
        4
    wizardoz  
       2018-05-16 12:45:32 +08:00
    json 字段加 json schema
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5529 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 06:07 · PVG 14:07 · LAX 23:07 · JFK 02:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.