Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在python django中将对象列表转储到json中_Javascript_Json_Python 2.7_Django 1.5 - Fatal编程技术网

Javascript 如何在python django中将对象列表转储到json中

Javascript 如何在python django中将对象列表转储到json中,javascript,json,python-2.7,django-1.5,Javascript,Json,Python 2.7,Django 1.5,这里我试图将json传递到javascript。但它返回空列表。 我需要将数据列表转储为json格式。但是json是空的。请帮助我 这是我的密码 views.py from django.utils import simplejson def student_search(request): location = rg('location') results = StudentProfile.objects.filter(Q(address_line1__icontains=loc

这里我试图将
json
传递到
javascript
。但它返回空列表。 我需要将数据列表转储为json格式。但是json是空的。请帮助我

这是我的密码 views.py

from django.utils import simplejson

def student_search(request):
   location = rg('location')
   results = StudentProfile.objects.filter(Q(address_line1__icontains=location) \
                                                        | Q(address_line2__icontains=location)).values()
   for result in results:
       students_list.append(result)
   if request.is_ajax():
       result = {

            'student': [student._json() for student in students_list]
            }
       return HttpResponse(
            simplejson.dumps(result), content_type="application/json",
            )
   return render_to_response("account/students.html",{'students_list' : students_list }, context_instance= RequestContext(request))
url.py

    url(r'student_search', 'account.views.student_search', name='student_searchview'),
模板

    <div class="hold"></div>
<input type="button" id="btnLoadMore" value="Load More"/>
<script type="text/javascript">
    $(document).ready(function () {
        $.get("/student_search/", function (data) {
            alert ("enter");
            alert(JSON.stringify(data));

        });

    });
    </script>

$(文档).ready(函数(){
$.get(“/student\u search/”,函数(数据){
警报(“输入”);
警报(JSON.stringify(数据));
});
});

99%的问题来自

results = StudentProfile.objects.filter(Q(address_line1__icontains=location) \
                                                    | Q(address_line2__icontains=location)).values()

您是否绝对确定这将返回一个列表,其中包括
bool
float
int
string
list
dict

噢,请正确缩进您的代码!我尝试了不使用
.values()
。但是我仍然没有得到打印它的权限