Django 在播客中双重转义标题

发布于 2024-11-06 05:33:37 字数 1132 浏览 3 评论 0 原文

我正在使用 Django 1.2,但在为播客生成良好的 XML 时遇到问题。任何包含单引号、双引号或与号的标题似乎都是双转义的,如下所示:

<title>Podcast: &amp;quot;But we had hoped...&amp;quot;</title>

这意味着它们显示如下:

Podcast: &quot;But we had hoped&quot;

我确实找到了 这张票,但它很久以前就被关闭了。

我正在使用此代码段生成我的提要,并且我只是在模型字段中填充一个值进入 self.title 位,如下所示:

class iTunesPodcastPost():
  def __init__(self, talk):
    self.id = talk.id
    self.approval_date_time = talk.created
    self.title = talk.title # Looks wonky
    self.summary = talk.details # Looks fine
    self.enclosure_url = talk.mp3.url
    self.enclosure_length = talk.mp3.size
    self.enclosure_mime_type = u'audio/mpeg'
    self.duration = '%s' % talk.seconds
    self.explicit = u'clean'
    self.info_url = talk.get_absolute_url()

如果有帮助,播客提要为 此处

I'm using Django 1.2, and am having trouble generating good XML for a podcast. Any titles containing single-quotes, double-quotes or ampersands appear to be double-escaped, looking like this:

<title>Podcast: &quot;But we had hoped...&quot;</title>

Which means that they show up like this:

Podcast: "But we had hoped"

I did find this ticket, but it was closed ages ago.

I'm generating my feed using this snippet, and I'm just stuffing a value in a model field into the self.title bit, like this:

class iTunesPodcastPost():
  def __init__(self, talk):
    self.id = talk.id
    self.approval_date_time = talk.created
    self.title = talk.title # Looks wonky
    self.summary = talk.details # Looks fine
    self.enclosure_url = talk.mp3.url
    self.enclosure_length = talk.mp3.size
    self.enclosure_mime_type = u'audio/mpeg'
    self.duration = '%s' % talk.seconds
    self.explicit = u'clean'
    self.info_url = talk.get_absolute_url()

In case it helps, the podcast feed is here.

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

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

发布评论

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

评论(1

澜川若宁 2024-11-13 05:33:37

这似乎是因为我未能在我的 Feed 子类上提供 item_title 方法。

一旦我补充道:

def item_title(self, item):
   return item.title

一切都很好。以前它默认调用我的项目的 __unicode__ 方法,结果很奇怪。这不是一个完全令人满意的解决方案(我仍然不知道为什么它坏了),但至少它现在有效。

This appears to have been because I failed to provide an item_title method on my Feed subclass.

Once I added:

def item_title(self, item):
   return item.title

All was well. Previously it had been defaulting to calling my item's __unicode__ method with bizarre results. Not an entirely satisfactory solution (I still don't know why it broke), but at least it works now.

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