Django: using <select multiple> and POST

前端 未结 5 1172
-上瘾入骨i
-上瘾入骨i 2020-12-04 08:22

I\'m using something like this in my template


                        
    
提交评论

  • 2020-12-04 08:37
    request.POST.getlist('services')
    
    0 讨论(0)
  • 2020-12-04 08:45

    Watch out! getlist method from QueryDict returns an empty list if the key doesn't exist. It does not throw an exception. http://bit.ly/MdgrUH

    0 讨论(0)
  • 2020-12-04 08:47

    you can get the expected list just by using...

    request.POST.getlist('fiel_name')
    
    0 讨论(0)
  • 2020-12-04 08:52

    Just FYI, I had to use:

        list = request.POST.getlist("items[]")
    

    because omitting the [] caused a blank list to be returned instead of the correct values. I'm using jQuery to fetch the values of a multiple select element, and jQuery appears to be adding the []

    0 讨论(0)
  • 提交回复
    热议问题