django - getlist() [英] django - getlist()

查看:93
本文介绍了django - getlist()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发布了这个问题 jQuery - 在发布请求中传递数组 ,我不会在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆