django自身提供的sitemap和feed实现样例
2016-07-07 14:26
489 查看
《DJANGO BY EXAMPLE》这书的例子真是精心全过的,
基本的WEB开发过程全覆盖啊。
跟着一步一步的弄就OK啦。。可以长很多知道的。
这次跟着作的是sitemap和feed功能。
sitemap.py
feeds.py
urls.py
样子:
基本的WEB开发过程全覆盖啊。
跟着一步一步的弄就OK啦。。可以长很多知道的。
这次跟着作的是sitemap和feed功能。
sitemap.py
from django.contrib.sitemaps import Sitemap from .models import Post class PostSitemap(Sitemap): changefreq = 'weekly' priority = 0.9 def items(self): return Post.published.all() def lastmod(self, obj): return obj.publish
feeds.py
from django.contrib.syndication.views import Feed from django.template.defaultfilters import truncatewords from .models import Post class LatestPostFeed(Feed): title = 'My blog' link = '/blog/' description = 'New posts of my blog.' def items(self): return Post.published.all()[:5] def item_title(self, item): return item.title def item_description(self, item): return truncatewords(item.body, 30)
urls.py
url(r'^sitemap\.xml', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'), url(r'^feed/$', LatestPostFeed(), name='post_feed'),
样子:
相关文章推荐
- 鼠标滑过弹出jquery在线客服
- Caffe之Classification
- Extjs combobox
- JS省市区三级联动
- jquery.serialize() 函数详解
- js时间转换+比较 Date.parse的兼容
- angularJS系列之$q处理异步通知
- 让Bootstrap 3兼容IE8浏览器
- html中设置元素不可编辑的方法以及readonly与disabled区别
- Angularjs使用 ajax实例
- jquery实现随着鼠标滚动固定导航栏
- Javascript Ajax实例
- JS基础之if判断语句
- 将数据转为json
- 关于nodejs中使用命令行启动报错的问题
- JavaScript图片轮播
- React同构直出原理浅析
- javascript 灵异现象之 if else 先后执行
- javascript 灵异现象之 if else 先后执行
- html5 form上传值