From b28758032ff44e8fea85ecbfb300b85cf3219db4 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 22 Jan 2019 14:26:05 +0800 Subject: [PATCH] 1 --- chapter2/mysite/myapp/apis.py | 4 +++- chapter2/mysite/myapp/urls.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/chapter2/mysite/myapp/apis.py b/chapter2/mysite/myapp/apis.py index febe22a..c0c3c67 100644 --- a/chapter2/mysite/myapp/apis.py +++ b/chapter2/mysite/myapp/apis.py @@ -2,6 +2,7 @@ import json from django.http import HttpResponse from myapp.models import * from myapp.utils import get_platform_info +from django.core.serializers import serialize def _render_json(data): response = HttpResponse(json.dumps(data, ensure_ascii=False), @@ -10,7 +11,8 @@ def _render_json(data): def crawl_info(request): _crawl_info = CrawlInfos.objects.order_by('-id').first() - return _render_json(_crawl_info) + data = json.loads(serialize('json',[_crawl_info]))[0] + return _render_json(data) def platform_info(request): diff --git a/chapter2/mysite/myapp/urls.py b/chapter2/mysite/myapp/urls.py index 9f3ae6b..b217af3 100644 --- a/chapter2/mysite/myapp/urls.py +++ b/chapter2/mysite/myapp/urls.py @@ -8,6 +8,6 @@ urlpatterns = [ path('crawl', views.crawl, name='crawl'), path('result', views.result, name='result'), path('api/crawl_info.json', apis.crawl_info), - path('api/platform_info.json', apis.crawl_info), + path('api/platform_info.json', apis.platform_info), ]