Django RSS 提要问题

发布于 2024-08-02 04:51:28 字数 775 浏览 6 评论 0原文

我正在开发一个博客应用程序,并尝试制作一个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愛放△進行李 2024-08-09 04:51:28

更改为:

class RSSFeed(Feed):
    title = settings.BLOG_NAME
    link = "/blog/"
    description = "Recent Posts"

    def items(self):
        return Story.objects.all().order_by('-created')[:10]

修复它。不确定我完全理解它..但是无论如何。 :)

Changing to:

class RSSFeed(Feed):
    title = settings.BLOG_NAME
    link = "/blog/"
    description = "Recent Posts"

    def items(self):
        return Story.objects.all().order_by('-created')[:10]

Fixed it. Not sure I totally understand it.. but whatev. :)

可遇━不可求 2024-08-09 04:51:28

def get_absolute_url(self):

在模型中定义了吗?

最好避免错误

if not obj:
    raise FeedDoesNotExist

另外,当提要结果不存在时,

have you defined

def get_absolute_url(self):

in the model?

also, it's nice to

if not obj:
    raise FeedDoesNotExist

to avoid errors when feed result is not present

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文