Skip to content

Commit 089927d

Browse files
author
yangxg
committed
Merge branch 'Step23_rss-feed' into demo
# Conflicts: # blogproject/urls.py
2 parents cec6b39 + 0228e2f commit 089927d

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

blog/feeds.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from django.contrib.syndication.views import Feed
2+
3+
from .models import Post
4+
5+
6+
class AllPostsRssFeed(Feed):
7+
# 显示在聚合阅读器上的标题
8+
title = "Django 博客教程演示项目"
9+
10+
# 通过聚合阅读器跳转到网站的地址
11+
link = "/"
12+
13+
# 显示在聚合阅读器上的描述信息
14+
description = "Django 博客教程演示项目测试文章"
15+
16+
# 需要显示的内容条目
17+
def items(self):
18+
return Post.objects.all()
19+
20+
# 聚合器中显示的内容条目的标题
21+
def item_title(self, item):
22+
return '[%s] %s' % (item.category, item.title)
23+
24+
# 聚合器中显示的内容条目的描述
25+
def item_description(self, item):
26+
return item.body

blog/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_context_data(self, **kwargs):
4242
"""
4343

4444
# 首先获得父类生成的传递给模板的字典。
45-
context = super().get_context_data(**kwargs)
45+
context = super(IndexView, self).get_context_data(**kwargs)
4646

4747
# 父类生成的字典中已有 paginator、page_obj、is_paginated 这三个模板变量,
4848
# paginator 是 Paginator 的一个实例,

blogproject/urls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
from django.contrib import admin
1818
from django.http import HttpResponse
1919

20+
from blog.feeds import AllPostsRssFeed
21+
2022
urlpatterns = [
2123
url(r'^admin/', admin.site.urls),
2224
url(r'', include('blog.urls')),
2325
url(r'', include('comments.urls')),
2426
url(r'^robots\.txt$', lambda r: HttpResponse('User-agent: *\nDisallow: /', content_type='text/plain')),
27+
url(r'^all/rss/$', AllPostsRssFeed(), name='rss'),
2528
]

templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ <h3 class="widget-title">标签云</h3>
133133
</div>
134134

135135
<div class="rss">
136-
<a href=""><span class="ion-social-rss-outline"></span> RSS 订阅</a>
136+
<a href="{% url 'rss' %}"><span class="ion-social-rss-outline"></span> RSS 订阅</a>
137137
</div>
138138
</aside>
139139
</div>

0 commit comments

Comments
 (0)