javascript - JSON parsing under django framework -
i'm learning both django , javascript
i passed json string python javascript , string got.
[{"model": "polls.question", "pk": 1, "fields": {"question_text": "anything", "pub_date": "2017-09-07t09:36:07z"}}, {"model": "polls.question", "pk": 2, "fields": {"question_text": "hi", "pub_date": "2017-09-07t10:01:39z"}}]
whenever use json.parse method javascript crashes
javascript:
let mylist = "{{ question_list_as_json | escapejs }}"; let temp = json.parse(mylist);
python:
question_list = question.objects.all() question_list_as_json = serializers.serialize('json', question_list) return render(request, 'polls/index.html', {'question_list': question_list, 'question_list_as_json': question_list_as_json})
in context question_list
in template question_list_as_json
, try it:
question_list = question.objects.all() question_list_as_json = serializers.serialize('json', question_list) context = { 'question_list': question_list, 'question_list_as_json': question_list_as_json } return render(request, 'polls/index.html', context)
wiki
Comments
Post a Comment