-1

尝试从 html 发布一个简单的帖子 ..

当我在 django 中收到请求时,我只是打印发布请求。(计数没有反映在我的输出中,不知道你..)

        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
4

1 回答 1

3

您必须使用 getlist ,例如:

request.POST.getlist('counts')

更多信息:Django:使用 <select multiple> 和 POST

于 2013-02-26T10:18:20.377 回答