Django syndication: How do I avoid description escaping?
-
19-09-2019 - |
Question
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:
<img src="http://localhost:8000/media/comics/001__.png"/>
How can I avoid this autoescaping?
Solution
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.
OTHER TIPS
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?