diff --git a/chapter2/init.sql b/chapter2/init.sql index 92efa8f..fb3465a 100644 --- a/chapter2/init.sql +++ b/chapter2/init.sql @@ -33,4 +33,12 @@ create table platform_infos ( ) comment='平台信息'; +create table news ( +`id` int(11) NOT NULL AUTO_INCREMENT, +comment_time varchar(255) comment '评论时间', +content varchar(1024) comment '评论内容', +comment_id varchar(255) comment '评论ID', + +PRIMARY KEY (`id`) +)comment='最新抓取的20条信息'; diff --git a/chapter2/mysite/myapp/models.py b/chapter2/mysite/myapp/models.py index db96617..05f7df4 100644 --- a/chapter2/mysite/myapp/models.py +++ b/chapter2/mysite/myapp/models.py @@ -27,4 +27,13 @@ class PlatformInfos(models.Model): class Meta: managed = False - db_table = 'platform_infos' \ No newline at end of file + db_table = 'platform_infos' + +class News(models.Model): + comment_time = models.CharField(max_length=255, blank=True, null=True) + content = models.CharField(max_length=1024, blank=True, null=True) + comment_id = models.CharField(max_length=255, blank=True, null=True) + + class Meta: + managed = False + db_table = 'news' \ No newline at end of file diff --git a/chapter2/mysite/myapp/templates/myapp/crawl.html b/chapter2/mysite/myapp/templates/myapp/crawl.html index 00b7ce5..7b1aed6 100644 --- a/chapter2/mysite/myapp/templates/myapp/crawl.html +++ b/chapter2/mysite/myapp/templates/myapp/crawl.html @@ -120,19 +120,9 @@ - 19月21日感染性腹泻发病:123人次2018-11-05 - 29月20日流行性感冒:57人次2018-11-03 - 39月19日:手足口病发病同比增长220%2018-11-01 - 49月18日登革热死亡:2人2018-10-29 - 59月17日流行性感冒:157人次2018-10-27 - 69月15日全区传染病发病人数较低2018-10-25 - 79月14日流行性感冒:157人次2018-10-23 - 89月13日全区传染病发病人数较低2018-10-21 - 99月12日流行性感冒:157人次2018-10-20 - 109月17日流行性感冒:157人次2018-10-27 - 119月15日全区传染病发病人数较低2018-10-25 - 129月14日流行性感冒:157人次2018-10-23 - 139月13日全区传染病发病人数较低2018-10-21 + {% for new in news %} + {{new.comment_id}}{{new.content}}{{new.comment_time}} + {% endfor %} diff --git a/chapter2/mysite/myapp/views.py b/chapter2/mysite/myapp/views.py index 754d63a..f398e96 100644 --- a/chapter2/mysite/myapp/views.py +++ b/chapter2/mysite/myapp/views.py @@ -13,7 +13,10 @@ def crawl(request): # info = scrapy_client.get_scrapy_info() crawl_info = CrawlInfos.objects.order_by('-id').first() platform_info = get_platform_info() - return render(request, 'myapp/crawl.html', {"crawl_info": crawl_info, "platform_info":json.dumps(platform_info)}) + news = News.objects.all() + return render(request, 'myapp/crawl.html', {"crawl_info": crawl_info, + "platform_info":json.dumps(platform_info), + "news": news}) def result(request): return render(request, 'myapp/result.html') \ No newline at end of file