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

本文通过《Django By Example》一书中的实例详细介绍了如何在Django项目中实现sitemap与feed功能。从代码实现角度出发,展示了sitemap.py与feeds.py文件的具体编写方式,并解释了各部分代码的作用及配置方法。
1154

被折叠的 条评论
为什么被折叠?



