views:

152

answers:

2

Hello. I'm trying to make a webcomic RSS feed with Django, but I can't put an image in the description field, because the html code gets escaped, even if it's in an {% autoescape off %} block.

Here is my description template:

{% autoescape off %}
<img src="{{obj.img.url}}"/>
{% endautoescape %}

And this is the result:

&lt;img src="http://localhost:8000/media/comics/001__.png"/&amp;gt;

How can I avoid this autoescaping?

A: 

This doesn't seem to have anything to do with autoescaping, as that would never 'escape' the hard-coded tags that you entered explicitly in your template as you have here.

I suspect there's something further down the line that is doing the escaping. Can you post the code that renders the template and does something with the result?

Daniel Roseman
+1  A: 

How can I avoid this autoescaping?

Actually, you need to keep this auto-escaping... Look carefully at any other rss feeds: xkcd.com/rss.xml

Quote from spec by the RSS Advisory Board:

A channel may contain any number of items. An item may represent a "story" -- much like a story in a newspaper or magazine; if so its description is a synopsis of the story, and the link points to the full story. An item may also be complete in itself, if so, the description contains the text (entity-encoded HTML is allowed; see examples), and the link and title may be omitted. All elements of an item are optional, however at least one of title or description must be present.

http://www.rssboard.org/rss-encoding-examples

alex vasi
Thank you VERY much.
Gonzalo Quero