【问题标题】:Entire array interpreted as last element in array整个数组解释为数组中的最后一个元素
【发布时间】:2013-07-13 22:43:43
【问题描述】:

我在我的 js 控制台中执行了以下语句:

$.post('/cp/remove-organizers/', {email_list:['test@test.org','test2@test.org']})

在我看来,然后我打印出request.POST 的值,我得到:

<QueryDict: {u'email_list[]': [u'test@test.org', u'test2@test.org']}>

没有什么不寻常的,对吧?事情是这样的:打印request.POST['email_list[]'] 的值(或者,request.POST.values() 返回:

u'test2@test.org'

为什么会发生这种情况,我该怎么做才能返回整个数组?

【问题讨论】:

    标签: jquery django json


    【解决方案1】:

    使用getlist 检索多个值。

    request.POST.getlist('email_list[]')
    

    这是documented behavior

    如果键有多个值,__getitem__() 返回最后一个值。

    【讨论】:

      猜你喜欢
      • 2012-10-24
      • 2017-01-11
      • 2022-09-29
      • 1970-01-01
      • 1970-01-01
      • 2017-02-27
      • 1970-01-01
      • 1970-01-01
      • 2012-12-03
      相关资源
      最近更新 更多