Здесь я пытаюсь передать json
в javascript
. Но он возвращает пустой список. мне нужно сбросить мой список данных, чтобы JSON format.but JSON является empty.please помочь мнеКак сбрасывать список объектов в json в python django
вот мой код 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))
urls.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>
О, пожалуйста, отпечатай свой код правильно! – math2001