1

我使用标准 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))
4

1 回答 1

0

在新闻模型中写道,

def get_absolute_url() 方法,返回每篇文章的url

于 2013-03-18T09:35:17.123 回答