【问题标题】:django - ckeditor bug renders text/string in raw html formatdjango - ckeditor 错误以原始 html 格式呈现文本/字符串
【发布时间】:2015-01-26 12:38:00
【问题描述】:

我正在使用 django ckeditor。在其编辑器中输入的任何文本/内容都会在网页上呈现原始 html 输出。

例如:这是网页上ckeditor字段(RichTextField)的渲染输出;

<p><span style="color:rgb(0, 0, 0)">this is a test file &rsquo;s forces durin</span><span style="color:rgb(0, 0, 0)">galla&rsquo;s good test is one that fails Thereafter, never to fail in real environment.&nbsp;</span></p>

我一直在寻找解决方案很长时间,但找不到一个:(有一些类似的问题,但没有一个能够提供帮助。如果提供任何建议的更改将会很有帮助需要更改的确切位置。不用说我是新手。

谢谢

【问题讨论】:

    标签: django django-apps django-ckeditor


    【解决方案1】:

    您需要将模板中包含html sn-p的相关变量标记为safe

    显然,您应该确定文本来自受信任的用户并且安全的,因为使用 safe 过滤器您正在禁用 Django 默认应用的安全功能(自动转义)。

    如果您的 ckeditor 是评论表单的一部分,并且您将输入的文本标记为 safe,则任何有权访问该表单的人都可以在您的页面中注入 Javascipt 和其他(可能令人讨厌的)内容。

    整个故事在官方文档中有很好的解释:https://docs.djangoproject.com/en/dev/topics/templates/#automatic-html-escaping

    【讨论】:

    • 谢谢...你是明星 :)
    • 嘿伙计,你知道如何设置模板中的文本样式吗?我尝试&lt;p class="bootstrap classes"&gt; {{ item.description|safe }} &lt;/p&gt;,但没有加载引导类(主要是垂直边距和填充)。我该如何设计它?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多