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>

最新文章

  1. 微信公众平台开发——微信授权登录(OAuth2.0)
  2. shell 条件测试语句三种方法
  3. JAVA多线程synchronized详解
  4. ecshop后台admin文件夹任意更改名
  5. 处理.NET中的内存泄露
  6. Linux Mono Asp.net 部署方案
  7. Configuration ReportNG with TestNG
  8. linux下的type命令
  9. AndroidUI 视图动画-缩放动画效果 (ScaleAnimation)
  10. JavaScript基础(更新第二波)
  11. python之---进程
  12. Charle抓包与wireshark使用
  13. 关于synchronized
  14. 用Docker解决坑爹的环境搭建系列——ubuntu16.04 SSH
  15. Angular动画
  16. 【java提高】---HashSet 与TreeSet和LinkedHashSet的区别
  17. leetcode — combination-sum
  18. 一道关于js声明变量,var和let的面试题
  19. PAT-Top1002. Business (35)
  20. SpringBoot之依赖注入DI

热门文章

  1. 8个学习.net的博客链接 (以前收藏过更多的,被百度新版搞没了,恨死了)
  2. div模拟dropdownlist控件 div下拉菜单
  3. 实现多线程sokect
  4. Bioconda安装与使用
  5. (2)JavaScript基础2
  6. AbstractAdvisingBeanPostProcessor---spring aop 处理器
  7. 【转】浅谈多核CPU、多线程、多进程
  8. UICollectionView专题
  9. ScutSDK 0.9版本发布
  10. 防止sql注入和跨站脚本攻击,跨站请求伪造以及一句话木马的学习记录