django实现rss订阅

发布时间:2019-09-30 12:00--阅读:814--评论:1条

1、写rss订阅的方法blog/feed.py

from django.contrib.syndication.views import Feed
# from django.urls import reverse
from .models import Article
 
class LatestEntriesFeed(Feed):
    title = "菲宇技术博客"
    link = "/blog/"
    description = "最新博客文章!"
 
    def items(self):
        return Article.objects.order_by('-created_time')[:5]
 
    def item_title(self, item):
        return item.title
 
    def item_description(self, item):
        return item.abstract
2、在urls.py中增加

from blog.feed import LatestEntriesFeed
 
url(r'^/latestfeed/$', LatestEntriesFeed()),    #RSS订阅
3、模板中增加right_side_bar.html

    <li>
        <a href="/latest/feed/"><i class="glyphicon glyphicon-plus"></i>RSS 订阅</a>
    </li>
4、前端显示效果

5、订阅后的文件

<rss version="2.0"><channel><title>菲宇技术博客</title><link>http://http://127.0.0.1:8000/blog/</link><description>最新博客文章!</description><atom:link href="https://blog.feiutech.com/feed" rel="self"/><language>zh-hans</language><lastBuildDate>Thu, 01 Aug 2019 02:28:24 +0000</lastBuildDate><item><title>Django 通用视图</title><link>http://http://127.0.0.1:8000/blog/article/2</link><description>located outside of the base path component</description><guid>http://http://127.0.0.1:8000/blog/article/2</guid></item><item><title>diango工程与应用、模板与静态路径配置</title><link>http://http://127.0.0.1:8000/blog/article/1</link><description>1、安装django</description><guid>http://http://127.0.0.1:8000/blog/article/1</guid></item></channel></rss>
 

Django连接mariadb数据库

 

微信公众号ID(feiutech)

微信公众号ID:feiutech

评论列表

265楼:Chew Mama always told you to chew your food thoroughly, and she was right <a href=https://bestcialis20mg.com/>cialis for sale online</a>

unpasse 于2023-01-11 15:17

共1条评论

我要评论

用户名:
邮箱: