当前位置 : 主页 > 编程语言 > python >

Django 学习笔记(六)

来源:互联网 收集:自由互联 发布时间:2022-06-15
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 fee


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


上一篇:Django URL解析的一些注意点
下一篇:没有了
网友评论