处理django post请求 - 一个值被分配而另一个未能分配不知道原因

时间:2013-02-26 10:09:28

标签: python django django-views

从html尝试一个简单的帖子。

当我在django收到请求时,我只是打印邮件请求。 (计数没有反映在我的输出dunno y ..)

        print "counterUpdate"
    print request.method
    print request.path
    print request.POST.get
    print "Expects data of counts in next line console print but it is empty"
    countValues=request.POST['counts'] # counts is not getting reflected in my output dunno y..
    updateType=request.POST['key']
    print countValues
    print updateType
    print "dddd1"
    for data in request.POST:
        print data
    print "Iteration Over"

以下内容:

counterUpdate
POST
/testapp/counterUpdate
<bound method QueryDict.get of <QueryDict: {u'counts': [u'100', u'100', u'', u''], u'key': [u'increase']}>>
Expects data of counts in next line console print but it is empty

increase
dddd1
counts
key
Iteration Over

1 个答案:

答案 0 :(得分:3)

您必须使用getlist,如:

request.POST.getlist('counts')

有关详细信息:Django: using <select multiple> and POST