How to resolve “Could not import django.contrib.syndication.views.feed” error in Django admin?
我已将Django版本更新为最新的每晚,并且在管理中收到以下错误;
1 2 | Could not import django.contrib.syndication.views.feed. View does not exist in module django.contrib.syndication.views. |
我在多个视图中也有此错误,因为确实不推荐使用
我只需要添加一个
1 | from django.contrib.syndication.views import Feed |
with
1 | from django.contrib.syndication.feeds import Feed |
问题在于,即使在Django源代码中,我也无法在任何地方找到对
错误的直接原因是
1 | /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py in get_callable, line 100 |
但是我也找不到任何东西。
希望有人可以提供帮助!
user643511建议该错误可能是在我自己的代码中,而不是Django。但是她没有指出真正的问题(由于我没有提供正确的信息,所以我理解了这个问题)。经过几天的挖掘,我才发现自己有
1 | url(r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}), |
在urls.py中。相反,我不得不使用
1 | url(r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}), |
在视图中输入大写字母F。Feed。
因此,如果有人遇到类似的麻烦,请检查urls.py。
也许您的代码有问题,我进行了一些测试,并且高级供稿生成框架运行良好。您只需要使用Feed类
1 | django.contrib.syndication.views.Feed |
这是一个简单的示例:在您的模型中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # -*- coding: utf8 -*- from django.utils.translation import ugettext as _ from django.contrib.syndication.views import Feed from django.db import models class Concept(models.Model): concept = models.IntegerField(unique=True, primary_key=True, verbose_name=_('Concepto')) description = models.CharField(max_length=255, verbose_name=_('Descripcion')) def __unicode__(self): return"%s" % ( self.description or self.concept ) class Meta: verbose_name = _('Concepto') verbose_name_plural = _('Conceptos') ordering = ['concept'] class LatestEntriesFeed(Feed): title ="My site news" link ="/sitenews/" description ="Updates on changes and additions." def items(self): return Concept.objects.all() def item_code(self, item): return item.code def item_description(self, item): return item.description |
并在您的网址中:
1 2 3 4 5 | from models import LatestEntriesFeed urlpatterns = patterns('', (r'^latest/feed/$', LatestEntriesFeed()), ) |
结果:
我的网站新闻http://example.com/sitenews/更改和附加内容的更新。es-esTue,2011年7月12日08:18:49 -0000
我希望有帮助。