Django之信息聚合

feeds.py

#coding:utf-8
__author__ = 'similarface'

from django.contrib.syndication.views import Feed
from django.template.defaultfilters import truncatewords
from .models import Post

class LastestPostsFeed(Feed):
    title='博客园'
    link='/myblog'
    description='新的文章'
    def items(self):
           return Post.published.order_by('-publish')[:5]
    def item_title(self, item):
           return item.title
    def item_description(self, item):
           return truncatewords(item.content, 30)

 urls.py

from django.conf.urls import url
from django.contrib import admin
from . import views
from .feeds import LastestPostsFeed

urlpatterns = [
    url(r'^$', views.post_list, name='post_list'),
    #url(r'^$', views.PostListView.as_view(), name='post_list'),
    url(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<post>[-\w \t]+)/$',views.post_detail,name='post_detail'),
    url(r'^(?P<post_id>\d+)/share/$', views.post_share,name='post_share'),
    url(r'^tag/(?P<tag_slug>[-\w]+)/$', views.post_list,name='post_list_by_tag'),
    url(r'^feed/$', LastestPostsFeed(), name='post_feed'),
]

http://127.0.0.1:8000/myblog/feed/

<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>博客园</title><link>http://cnblog.com/myblog</link><description>新的文章</description><atom:link href="http://cnblog.com/myblog/feed/" rel="self"></atom:link><language>zh_CN</language><lastBuildDate>Wed, 20 Apr 2016 04:01:28 -0000</lastBuildDate><item><title>python代码</title><link>http://cnblog.com/myblog/2016/04/20/python%E4%BB%A3%E7%A0%81/</link><description>""" Python Markdown =============== Python Markdown converts Markdown to HTML and can be used as a library or called from the command line. ## Basic usage as a module: import ...</description><guid>http://cnblog.com/myblog/2016/04/20/python%E4%BB%A3%E7%A0%81/</guid></item><item><title>ssss</title><link>http://cnblog.com/myblog/2016/04/19/ssss/</link><description>ssss</description><guid>http://cnblog.com/myblog/2016/04/19/ssss/</guid></item><item><title>python 操作FTP</title><link>http://cnblog.com/myblog/2016/04/19/python%20%E6%93%8D%E4%BD%9CFTP/</link><description>listdir() strips dir path, any failure ends script 上传一个目录 """ localfiles = os.listdir(self.localdir) # listdir is local listing for localname in localfiles: localpath = os.path.join(self.localdir, localname) print('uploading', localpath, 'to', localname, ...</description><guid>http://cnblog.com/myblog/2016/04/19/python%20%E6%93%8D%E4%BD%9CFTP/</guid></item><item><title>分区容量大于16TB的格式化</title><link>http://cnblog.com/myblog/2016/04/19/%E5%88%86%E5%8C%BA%E5%AE%B9%E9%87%8F%E5%A4%A7%E4%BA%8E16TB%E7%9A%84%E6%A0%BC%E5%BC%8F%E5%8C%96/</link><description>The demo system My demo system consists of one large LUNof 18 TB encapsulated in LVM with a logical volume of 17 TB on a Oracle Enterprise Linux (OEL 5.5): ...</description><guid>http://cnblog.com/myblog/2016/04/19/%E5%88%86%E5%8C%BA%E5%AE%B9%E9%87%8F%E5%A4%A7%E4%BA%8E16TB%E7%9A%84%E6%A0%BC%E5%BC%8F%E5%8C%96/</guid></item><item><title>数据挖掘之协同过滤</title><link>http://cnblog.com/myblog/2016/04/19/%E6%95%B0%E6%8D%AE%E6%8C%96%E6%8E%98%E4%B9%8B%E5%8D%8F%E5%90%8C%E8%BF%87%E6%BB%A4/</link><description>数据挖掘之协同过滤</description><guid>http://cnblog.com/myblog/2016/04/19/%E6%95%B0%E6%8D%AE%E6%8C%96%E6%8E%98%E4%B9%8B%E5%8D%8F%E5%90%8C%E8%BF%87%E6%BB%A4/</guid></item></channel></rss>

 

posted @ 2016-04-20 12:04  similarface  阅读(268)  评论(0编辑  收藏  举报