django自身提供的sitemap和feed实现样例
2024-08-27 15:50:27
《DJANGO BY EXAMPLE》这书的例子真是精心全过的,
基本的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'),
样子:
最新文章
- 利用Aspose.Pdf将扫描的电子书修改为适合在kindle上查看
- manifest package
- context switches per second 上下文切换
- Redis使用详细教程(转)
- MongoDB 3 + Windows 7 X64安装及配置
- Java的函数与函数重载
- find the Nth highest salary(寻找第N高薪水)
- 方法--printStackTrace()
- RPC-非阻塞通信下的同步API实现原理,以Dubbo为例
- htmlUtil 网页爬取工具
- sql中检查时间是否重叠
- 微信小程序开发---自定义组件
- Python迷宫游戏(基础版)
- [maven] ";Dynamic Web Module 3.0 requires Java 1.6 or newer."; OR ";JAX-RS (REST Web Services) 2.0 requires Java 1.6 or newer.";
- CF 1047 C. Enlarge GCD
- Java四中引用
- Javascript之继承(原型链方式)
- jQuery统计上传文件的大小
- [svc]Linux中Swap与Memory内存简单介绍
- python学习笔记一和PHP的一些对比
热门文章
- C#上机作业及代码Question2
- ACM_求N^N的前5位数和后5位数(数论)
- .net引用System.Data.SQLite操作SQLite
- 306 Additive Number 加法数
- Storm概念学习系列之storm的优化
- Scala-基础-数组(1)
- js this 和 event 的区别
- dutacm.club_1087_Common Substrings_(KMP)_(结合此题通俗理解kmp的next数组)
- Anniversary Cake
- Jenkins系列之Jenkins的安装(一)