django 获取 POST 请求值的几种方法
2个回答
展开全部
1、django获取post过来的多个键值对:
Ajax:
var languages = {};
languages['english'] = ['mark', 'james'];
languages['spanish'] = ['amy', 'john'];
$.ajax({
type: 'POST',
url: '/save/',
data: languages,
dataType: 'json'
});
Django Views.py
if request.is_ajax() and request.method == 'POST':
for key in request.POST:
print key
valuelist = request.POST.getlist(key)
print valuelist
---------------------
fiddle:
name=june; age=26;
---------------------
views.py
16 for key in request.POST: 17 print key 18 valuelist = request.POST.getlist(key) 19 print valuelist
age [u'26'] [04/Apr/2012 10:58:11] "POST /getuin/ HTTP/1.1" 200 20
2、一次加载所有值:
def view_example(request):
data=simplejson.loads(request.raw_post_data)
Ajax:
var languages = {};
languages['english'] = ['mark', 'james'];
languages['spanish'] = ['amy', 'john'];
$.ajax({
type: 'POST',
url: '/save/',
data: languages,
dataType: 'json'
});
Django Views.py
if request.is_ajax() and request.method == 'POST':
for key in request.POST:
print key
valuelist = request.POST.getlist(key)
print valuelist
---------------------
fiddle:
name=june; age=26;
---------------------
views.py
16 for key in request.POST: 17 print key 18 valuelist = request.POST.getlist(key) 19 print valuelist
age [u'26'] [04/Apr/2012 10:58:11] "POST /getuin/ HTTP/1.1" 200 20
2、一次加载所有值:
def view_example(request):
data=simplejson.loads(request.raw_post_data)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询