【发布时间】:2014-04-28 15:47:08
【问题描述】:
我收到json不可序列化的错误。
views.py
def get_post(request):
if request.is_ajax():
if request.method=="GET":
craves = CraveData.objects.filter(person=request.user)
print craves
response = json.dumps({"craves":craves})
return HttpResponse(response,mimetype="application/json")
渴望.html
function next(){
alert("you in")
$.ajax({
url: "/crave/get_post/",
type: "GET",
data: "",
success: function(response){
alert('success');
alert(response.craves)
//$('.ajaxProgress').html(response.HTML_USER);
$('.ajaxProgress').html(response.craves);
},
error:function(){
alert('some error');
}
});
}
我收到TypeError: [<CraveData: Gaurav>, <CraveData: Rahul>] is not JSON serializable
但是当我试图得到时
craves = len(CraveData.objects.filter(person=request.user))
我得到了价值。请帮我在模板中获取对象。
【问题讨论】: