Django RSS 提要问题
我正在开发一个博客应用程序,并尝试制作一个简单的 RSS 提要系统功能。然而,我遇到了一个奇怪的错误,这对我来说没有多大意义。我明白可能会发生什么,但我不明白为什么。我的 RSS Feed 类如下:
class RSSFeed(Feed):
title = settings.BLOG_NAME
description = "Recent Posts"
def items(self):
return Story.objects.all().order_by('-created')[:10]
def link(self, obj):
return obj.get_absolute_url()
但是我收到以下错误(完整堆栈跟踪位于 http://dpaste.com/82510 /):
AttributeError: 'NoneType' object has no attribute 'startswith'
这让我相信它没有收到任何对象。但是,我可以放到 shell 中并获取那些 Story 对象,并且可以迭代它们返回绝对 url,没有任何问题。因此,Feed 的两个部分似乎都起作用,只是在 Feed 形式时不起作用。此外,我添加了一些日志记录,并且可以确认在访问 feed 链接时从未输入 items 函数。我希望我只是忽略了一些简单的事情。预先感谢您的任何/所有帮助。
I'm working on a blogging application, and trying to made just a simple RSS feed system function. However, I'm running into an odd bug that doesn't make a lot of sense to me. I understand what's likely going on, but I don't understand why. My RSS Feed class is below:
class RSSFeed(Feed):
title = settings.BLOG_NAME
description = "Recent Posts"
def items(self):
return Story.objects.all().order_by('-created')[:10]
def link(self, obj):
return obj.get_absolute_url()
However I received the following error (full stack trace at http://dpaste.com/82510/):
AttributeError: 'NoneType' object has no attribute 'startswith'
That leads me to believe that it's not receiving any objects whatsoever. However, I can drop to a shell and grab those Story objects, and I can iterate through them returning the absolute url without any problems. So it would seem both portions of the Feed work, just not when it's in feed form. Furthermore, I added some logging, and can confirm that the items function is never entered when visiting the feeds link. I'm hoping I'm just overlooking something simple. Thanks in advance for any/all help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改为:
修复它。不确定我完全理解它..但是无论如何。 :)
Changing to:
Fixed it. Not sure I totally understand it.. but whatev. :)
你
在模型中定义了吗?
最好避免错误
另外,当提要结果不存在时,
have you defined
in the model?
also, it's nice to
to avoid errors when feed result is not present