django - getlist() [英] django - getlist()
问题描述
我刚刚发布了这个问题 jQuery - 在 post 请求中传递数组,我在post请求中不发送数组,但是jQuery代码没有问题.
I just posted this question jQuery - passing arrays in post request, where I don't to send arrays in post request, but there is no problem in jQuery code.
问题在于在 django 中接收 POST 请求.我喜欢这个.
The problem is with receiving the POST request in django. I did like this.
def portfolio_add(request):
ukeys = request.POST.getlist('ukeys')
........etc.......
但是我得到的 ukeys 值是 u'[]'
.当我只检查 request.POST
时,我得到的值为 u"<QueryDict: {u'ukeys[]': [u'68c04', u'16149']}>"
But I'm getting ukeys values as u'[]'
. When I checked with just request.POST
I got the values as u"<QueryDict: {u'ukeys[]': [u'68c04', u'16149']}>"
那么,如何在 Django 中以列表的形式获取这些值?
So, How to get those values as a list in Django?
谢谢!
推荐答案
jQuery POST 的数组带有 []
后缀,因为 PHP 和一些 web 框架理解这个约定,并在服务器端自动为您服务.Django 不能那样工作,但您应该能够通过以下方式访问数据:
jQuery POST's arrays with the []
suffix because PHP and some web frameworks understand that convention, and re-build the array on the server-side for you automatically. Django doesn't work that way, but you should be able to access the data via:
ukeys = request.POST.getlist('ukeys[]')
这篇关于django - getlist()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!