Django 生成带有描述的 RSS feed
我正在尝试生成完整的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果有人遇到此问题,问题出在模板的链接上。
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"
我认为您正在尝试通过电子邮件订阅提要...正确吗?
为此,您需要添加一些内容。
首先,导入“content”扩展。这是在开始的
元素中完成的,如下所示:然后,将完整的描述添加到如下所示的元素中:
这是对所需常规描述标记的补充通过 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:Then, add the full desription to an element like this:
This is in addition to the regular description tag required by RSS and can be added to each
<item>
element.