简体   繁体   中英

Django double-escaping titles in podcasts

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: &amp;quot;But we had hoped...&amp;quot;</title>

Which means that they show up like this:

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

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM