添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
耍酷的啄木鸟  ·  Imports - Post Import ...·  1 周前    · 
行走的酱肘子  ·  requests(一): ...·  4 天前    · 
深情的黑框眼镜  ·  Zebra Support Community·  4 月前    · 
机灵的木瓜  ·  python ...·  4 月前    · 
帅气的松球  ·  getLocationInWindow ...·  1 年前    · 

I have this in my front-end (using AlpineJS to go through a loop) :

x-model="rule.protocol"
:name="'protocol[' + rule.pk + ']'"
:value="rule.protocol"

So the print(request.POST) is like this :

<QueryDict: {'csrfmiddlewaretoken': ['xxx'], 'rules[]': ['18580', '18581', '18582', '18583'],
'type[18580]': ['SSH'], 'protocol[18580]': ['TCP'], 'port_range[18580]': ['343434'],
'ip_range[18580]': ['Custom'], 'source_destination[18580]': ['172.16.16.0/24'],

I want request.POST['type[18580]'] as request.POST['type'][18580] and not as a string (‘type[18580]’)

data['form'] = TestForm() if request.method == "POST": # request.POST.getlist("array") by using this you can get list of data print(request.POST.getlist("array")) data['form'] = TestForm(request.POST) if request.method == "POST": if data['form'].is_valid(): return redirect('.') return render(request, html_path, data)

Let me simplify this :

I have a <form> which has 3 input fields :

<input type="text" name="foo[10]" value="a" />
<input type="text" name="foo[22]" value="b" />
<input type="text" name="foo[35]" value="c" />

How do I access it as request.POST['foo'][22] instead of request.POST['foo[22]']

I guess I’ll revert to :

<input type="text" name="age" value="a" />
<input type="text" name="age" value="b" />
<input type="text" name="age" value="c" />

and ages= request.POST.getlist('age')