我正在尝试让 RSS 与 django 一起使用
我有一个社交书签应用程序。
当我尝试在 localhost:8000/feeds/recent/ 访问 rss 页面时
我收到以下错误:
Could not import django.contrib.syndication.views.feed. View does not exist in module django.contrib.syndication.views.
我正在使用 python 2.7.3 和 django 1.5.1
我只会展示我认为相关的代码。
我在 feeds.py 中有以下代码
from django.contrib.syndication.views import Feed
from bookmarks.models import Bookmark
class RecentBookmarks(Feed):
title = 'Django Bookmarks | Recent Bookmarks'
link = '/feeds/recent/'
description = 'Recent bookmarks posted to Django Bookmarks'
def items(self):
return Bookmark.objects.order_by('id')[:10]
urls.py 有以下代码,我省略了不相关的 url。
import os.path
from django.conf.urls.defaults import *
from bookmarks.views import *
from bookmarks.feeds import *
from django.views.generic import TemplateView
from bookmarks.models import Link, Bookmark, Tag, SharedBookmark
site_media = os.path.join(
os.path.dirname(__file__), 'site_media'
)
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
admin.site.register(Link)
class BookmarkAdmin(admin.ModelAdmin):
list_display = ('title', 'link', 'user')
list_filter = ('user',)
ordering = ('title',)
search_fields = ('title',)
admin.site.register(Bookmark, BookmarkAdmin)
admin.site.register(Tag)
admin.site.register(SharedBookmark)
feeds = {
'recent': RecentBookmarks
}
urlpatterns = patterns('',
# Feeds
(r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed',
{'feed_dict': feeds }),
)
models.py 如下所示:
from django.db import models
from django.contrib.auth.models import User
class Link(models.Model):
url = models.URLField(unique=True)
def __str__(self):
return self.url
class Bookmark(models.Model):
title = models.CharField(max_length=200)
user = models.ForeignKey(User)
link = models.ForeignKey(Link)
def __str__(self):
return '%s %s' % (self.user.username, self.link.url)
def get_absolute_url(self):
return self.link.url