简体   繁体   English

Django联合:我如何避免描述转义?

[英]Django syndication: How do I avoid description escaping?

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. 我正在尝试使用Django创建一个webcomic RSS提要,但我不能在描述字段中放置一个图像,因为html代码会被转义,即使它位于{%autoescape off%}块中。

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"/&gt;

How can I avoid this autoescaping? 我怎样才能避免这种自动转换?

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 实际上,你需要保持这种自动转义...仔细查看任何其他rss提要: xkcd.com/rss.xml

Quote from spec by the RSS Advisory Board: 来自 RSS顾问委员会的规范报价

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. 项目本身也可以是完整的,如果是,则描述包含文本( 允许实体编码的HTML ; 参见示例 ),并且可以省略链接和标题。 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 http://www.rssboard.org/rss-encoding-examples

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. 这似乎与autoescaping没有任何关系,因为它永远不会“逃脱”您在模板中明确输入的硬编码标签。

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? 你可以发布渲染模板的代码并对结果做些什么吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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