Django框架第六部分学习笔记有哪些内容?
- 内容介绍
- 文章标签
- 相关推荐
本文共计327个文字,预计阅读时间需要2分钟。
Django 1.5 版本中,`from django.contrib.syndication.views import Feed` 的使用变更如下:
1. 1.5 版本中,只有 `views.py` 文件存在,其他相关文件都被删除。
2.以下是一个简单的示例,摘自一个假设的警察巡逻新闻网站,描述了如何使用 `Feed`:
python
from django.contrib.syndication.views import Feedclass LatestEntriesFeed(Feed): title=Latest Police Beat News link=/news/ description=Latest news from the police beat.
def items(self): return NewsItem.objects.order_by('-pub_date')[:10]
def item_title(self, item): return item.title
def item_description(self, item): return item.description
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 Feedfrom 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以前
本文共计327个文字,预计阅读时间需要2分钟。
Django 1.5 版本中,`from django.contrib.syndication.views import Feed` 的使用变更如下:
1. 1.5 版本中,只有 `views.py` 文件存在,其他相关文件都被删除。
2.以下是一个简单的示例,摘自一个假设的警察巡逻新闻网站,描述了如何使用 `Feed`:
python
from django.contrib.syndication.views import Feedclass LatestEntriesFeed(Feed): title=Latest Police Beat News link=/news/ description=Latest news from the police beat.
def items(self): return NewsItem.objects.order_by('-pub_date')[:10]
def item_title(self, item): return item.title
def item_description(self, item): return item.description
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 Feedfrom 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以前

