《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'),

样子:

最新文章

  1. 利用Aspose.Pdf将扫描的电子书修改为适合在kindle上查看
  2. manifest package
  3. context switches per second 上下文切换
  4. Redis使用详细教程(转)
  5. MongoDB 3 + Windows 7 X64安装及配置
  6. Java的函数与函数重载
  7. find the Nth highest salary(寻找第N高薪水)
  8. 方法--printStackTrace()
  9. RPC-非阻塞通信下的同步API实现原理,以Dubbo为例
  10. htmlUtil 网页爬取工具
  11. sql中检查时间是否重叠
  12. 微信小程序开发---自定义组件
  13. Python迷宫游戏(基础版)
  14. [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."
  15. CF 1047 C. Enlarge GCD
  16. Java四中引用
  17. Javascript之继承(原型链方式)
  18. jQuery统计上传文件的大小
  19. [svc]Linux中Swap与Memory内存简单介绍
  20. python学习笔记一和PHP的一些对比

热门文章

  1. C#上机作业及代码Question2
  2. ACM_求N^N的前5位数和后5位数(数论)
  3. .net引用System.Data.SQLite操作SQLite
  4. 306 Additive Number 加法数
  5. Storm概念学习系列之storm的优化
  6. Scala-基础-数组(1)
  7. js this 和 event 的区别
  8. dutacm.club_1087_Common Substrings_(KMP)_(结合此题通俗理解kmp的next数组)
  9. Anniversary Cake
  10. Jenkins系列之Jenkins的安装(一)