【发布时间】:2014-02-11 12:10:03
【问题描述】:
我正在以这种方式创建 json 数据:
def get_all_from_database():
urls = Url.objects.all()
ips = Ip.objects.all()
urls_json = serializers.serialize('json', urls)
ips_json = serializers.serialize('json', ips)
return urls_json, ips_json
我尝试使用 ajax 将其传递给前端:
@csrf_exempt
def send_results(request):
if request.is_ajax():
address = request.POST.get('url')
urls, ips = get_all_from_database()
return HttpResponse(urls, ips)
js代码:
$.ajax({
type: "POST",
url: "/link_finder/send_results/",
data: {
url : web_page,
},
success: function(data) {
alert(data);
},
error: function(xhr, textStatus, errorThrown) {
alert("Please report this error: "+errorThrown+xhr.status+xhr.responseText);
}
我得到这个错误:
INTERNAL SERVER ERROR500AttributeError at /link_finder/send_results/
'str' object has no attribute 'iteritems'
为什么?我应该改变什么?
【问题讨论】:
-
您的日志中产生的完整回溯是什么?
-
你试过使用 json.dumps() 吗?
-
从终端粘贴日志
-
我没有登录终端,只是 "POST /link_finder/send_results/ HTTP/1.1" 500 11640
标签: javascript python json django