Django的。 RSS订阅

时间:2013-03-07 08:21:12

标签: django rss

我使用标准django RSS:

from django.contrib.syndication.views import Feed

class RSSFeed(Feed):
    title = "MyBlog"
link = "/news/"
description = "Last news:"
item_link=link

    def items(self):
        return BlogPost.objects.all()[:10]

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

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

网址:

(r'^feed/$', RSSFeed()),

结果我得到http://mysite.com/news/每个帖子。如何为每个帖子创建唯一链接?

帖子有自己的网址:

url(r'^news/(?P<slug>[^\.]+).html', view_post, name='view_blog_post'),

视图:

def view_post(request, slug):
return render_to_response('post.html', {
    'post': get_object_or_404(BlogPost, slug=slug),
}, context_instance=RequestContext(request))

1 个答案:

答案 0 :(得分:0)

在新闻模特中写下,

def get_absolute_url()方法,它返回每篇文章的网址