【问题标题】:Django. RSS feed姜戈。 RSS订阅
【发布时间】:2013-03-07 08:21:11
【问题描述】:

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

【问题讨论】:

    标签: django rss


    【解决方案1】:

    在新闻模型中写,

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

    【讨论】:

      猜你喜欢
      • 2020-08-17
      • 1970-01-01
      • 2011-01-27
      • 2016-01-06
      • 2014-06-02
      • 1970-01-01
      • 2011-07-22
      • 2010-10-12
      • 2010-10-25
      相关资源
      最近更新 更多