django-cms 删除 ;文本内容的标签

发布于 2024-10-16 12:32:03 字数 221 浏览 5 评论 0原文

我正在使用 django-cms,并向页面添加一段文本内容(使用标准文本插件)。然后在那段文本上,我进入 html 模式并添加 并保存插件并保存页面。

现在,在网站上,我看到我所做的页面更改,但 img 标签已被删除。

知道为什么会发生这种情况吗?我尝试过 wymeditor 和 fckeditor,它都发生在两者下。

I'm using django-cms, and I add a piece of text content (using the standard text plugin) to a page. Then on that piece of text, I go into html mode and add <img src="/foo/bar.png" /> and save the plugin and save the page.

On the site, now, I see the page changes I've made, but the img tag has been stripped out.

Any idea why this is happening? I've tried wymeditor and fckeditor and it happens under both.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

她如夕阳 2024-10-23 12:32:03

我相信在 Django CMS 中,HTML 清理发生在 Django 模板层之前。我查看了我的数据库,发现 HTML 中的“”标签正在被清理。

我认为这发生在 插件(Django CMS 用于表示其内容位的短语)层。我假设要添加 HTML,您正在使用 文本插件。查看 的源代码文本插件模型的 clean 方法

def clean(self):
    self.body = clean_html(self.body, full=False)

它调用 cms.utils.clean_html,它又使用 html5lib 来清理 HTML。

解决此问题的一种方法是创建一个 自定义插件 继承自 Text 插件,并重新实现了不执行此清理操作的 clean 方法。

I believe that in Django CMS, the HTML cleaning happens before the Django Template layer. I took a look in my database and found that a "" tag in my HTML was being sanitized.

I think this happens at the Plugin (the phrase Django CMS uses for its bits of content) layer. I'm assuming that to add HTML, you're using the Text plugin. Looking at the source for the clean method of the Text plugin model:

def clean(self):
    self.body = clean_html(self.body, full=False)

It calls cms.utils.clean_html, which in turn uses html5lib to sanitize the HTML.

One way to work around this would be to create a custom plugin that inherits from the Text plugin and re-implements the clean method that doesn't do this sanitization.

暗地喜欢 2024-10-23 12:32:03

在 Django 中,默认情况下,字符串在输出到网页之前会被清理。我怀疑 Django-CMS 将插件视为未经处理的用户数据,因此 Django 模板系统从插件中删除了 HTML 字符。

Django 模板文档: http://docs.djangoproject.com /en/dev/ref/templates/builtins/?from=olddocs

请注意第一项,autoescape。我怀疑插件正在通过该过滤器运行。

抱歉,我没有更多具体信息。我不是 Django-CMS 人。

In Django, strings are sanitized before being output onto a webpage by default. I suspect Django-CMS treats plugins like unsanitized user data, so the Django Template system strips out an HTML characters from the plugin.

Django Template Docs: http://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs

Note the very first item, autoescape. I suspect plugins are being run through that filter.

Sorry, I don't have any more specifics. I'm not a Django-CMS guy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文