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