1
장고 직렬화를 사용하여 JSON 객체를 성공적으로 생성하고 있습니다. 나는이보기에 그렇게 :jQuery를 사용하여 장고의 직렬화로 생성 된 JSON 파일 읽기
def fetch_content(request, content_id):
content = serializers.serialize('json', [ContentQueue.objects.get(id=content_id)], fields=('title', 'description'))
mimetype = 'application/javascript; charset=utf8'
return HttpResponse(content, mimetype)
이이 같은 JSON을 뱉어 :
api_url = /fetch-content/ + content_id;
$.getJSON(api_url, function(json) {
var type = json.title;
var desc = json.description;
<then I display the content onscreen>
: 나는 아래 jQuery 코드이 JSON 파일을 읽으려고
[{"pk": 24, "model": "contentqueue", "fields": {"description": "Aerosmith frontman Steven Tyler was typically gabby...", "title": "Steven Tyler Tells All: On The Cover of Rolling Stone"}}]
json.fields.title로 내용에 액세스하려고 시도했지만 작동하지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
아아 스냅. 감사! – tabdon