LOADING

Follow me

Django 学习笔记(六)
十一月 21, 2013|IT

Django 学习笔记(六)


Django1.5 关于from django.contrib.syndication.views import  Feed 的变更

1.5中只有views.py一个文件,其他的在1.5都删除了


A simple example


This simple example, taken from a hypothetical police beat news site describes a feed of the latest five news items:

from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse
from policebeat.models import NewsItem

class LatestEntriesFeed(Feed):
    title = "Police beat site news"
    link = "/sitenews/"
    description = "Updates on changes and additions to police beat central."

    def items(self):
        return NewsItem.objects.order_by('-pub_date')[:5]

    def item_title(self, item):
        return item.title

    def item_description(self, item):
        return item.description

    # item_link is only needed if NewsItem has no get_absolute_url method.
    def item_link(self, item):
        return reverse('news-item', args=[item.pk])


1.4以前

from django.contrib.syndication.views import feed


版权声明:本文为博主原创文章,未经博主允许不得转载。

no comments
Share

发表评论