Django 生成带有描述的 RSS feed

发布于 2024-08-29 20:01:27 字数 822 浏览 10 评论 0原文

我正在尝试生成完整的 rss 提要,但是在邮件中加载提要时,它只显示标题,底部有一个“阅读更多”链接。我尝试了几种不同的选择。但似乎都不起作用。

我想通过我的模型中的多个提要的组合来生成提要。

这是我尝试过的代码:

class LatestEvents(Feed):
    description_template = "events_description.html"

    def title(self):
        return "%s Events" % SITE.name

    def link(self):
        return '/events/'

    def items(self):
        events = list(Event.objects.all().order_by('-published_date')[:5])
        return events

    author_name = 'Latest Events'

    def item_pubdate(self, item):
        return item.published_date

在存储在 TEMPLATE_ROOT/feeds/ 中的模板中,

{{ obj.description|safe }}
<h1>Event Location Details</h1>
{{ obj.location|safe }}

即使我对描述进行硬编码,它也不起作用。下面的解决方案不起作用,并且在 Firefox 中测试 feed 也不会显示内容。

基本上我想创建一个完整的提要。

I am trying to generate a full rss feed, however when loading the feed in Mail, it just shows the title, with a read more link at the bottom. I have tried several different options. But none seem to work.

I would like to generate the feed with a combination of several feeds in my modl.

Here is the code i have tried:

class LatestEvents(Feed):
    description_template = "events_description.html"

    def title(self):
        return "%s Events" % SITE.name

    def link(self):
        return '/events/'

    def items(self):
        events = list(Event.objects.all().order_by('-published_date')[:5])
        return events

    author_name = 'Latest Events'

    def item_pubdate(self, item):
        return item.published_date

And in my template which is stored in TEMPLATE_ROOT/feeds/

{{ obj.description|safe }}
<h1>Event Location Details</h1>
{{ obj.location|safe }}

Even if i hard code the description it does not work. The solution below does not work, and testing the feed in Firefox also do not display the content.

Basically i want to create a full feed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

如日中天 2024-09-05 20:01:28

如果有人遇到此问题,问题出在模板的链接上。

IE
description_template = "events_description.html"

我假设 django 会处理检查模板目录,但是您必须指定模板所在的位置。

description_template =“events/events_description.html”

If anyone comes across this, the problem was the link to the template.

i.e
description_template = "events_description.html"

I assumed django would handle checking the template directory, however you have to specify where the template is located.
i.e

description_template = "events/events_description.html"

走走停停 2024-09-05 20:01:28

我认为您正在尝试通过电子邮件订阅提要...正确吗?

为此,您需要添加一些内容。

首先,导入“content”扩展。这是在开始的 元素中完成的,如下所示:

<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">

然后,将完整的描述添加到如下所示的元素中:

<content:encoded><![CDATA[
  <p>The full description goes here bla bla bla.</p> 
  <p>You can use HTML tags too.</p>
]]></content:encoded>

这是对所需常规描述标记的补充通过 RSS 生成,并且可以添加到每个 元素中。

I take it that you are trying to subscribe to the feed via email... correct?

To do this, you need to add a couple things.

First, import the "content" extension. This is done in the opening <rss> element like this:

<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">

Then, add the full desription to an element like this:

<content:encoded><![CDATA[
  <p>The full description goes here bla bla bla.</p> 
  <p>You can use HTML tags too.</p>
]]></content:encoded>

This is in addition to the regular description tag required by RSS and can be added to each <item> element.

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