如何在 django-cms 中使用 iframe [英] How to use iframes in django-cms

查看:32
本文介绍了如何在 django-cms 中使用 iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个好的解决方案,使最终用户可以在模板占位符中插入 iframe (Soundcloud).我想过使用 djangocms-txt-ckeditor 插件.在文档中,它说要使用可配置的消毒剂来完成此操作:

I am looking for a good solution to make it possible for endusers to insert iframes (Soundcloud) in a template placeholder. I thought about using the djangocms-txt-ckeditor plugin. In it documentation it says to use the configurable sanitizer to accomplish this:

djangocms-text-ckeditor 使用 html5lib 来清理 HTML 以避免安全问题 >并检查正确的 HTML 代码.清理可能会去除对某些 > 用例有用的标签,例如 iframe;您可以通过>覆盖 TEXT_ADDITIONAL_TAGS 和 TEXT_ADDITIONAL_ATTRIBUTES 设置来自定义标签和属性:

djangocms-text-ckeditor uses html5lib to sanitize HTML to avoid security issues >and to check for correct HTML code. Sanitisation may strip tags usesful for some >use cases such as iframe; you may customize the tags and attributes allowed by >overriding the TEXT_ADDITIONAL_TAGS and TEXT_ADDITIONAL_ATTRIBUTES settings:

TEXT_ADDITIONAL_TAGS = ('iframe',)
TEXT_ADDITIONAL_ATTRIBUTES = ('scrolling', 'allowfullscreen', 'frameborder')

TEXT_ADDITIONAL_TAGS = ('iframe',)
TEXT_ADDITIONAL_ATTRIBUTES = ('scrolling', 'allowfullscreen', 'frameborder')

我确实像那样编辑了我的项目中的 settings.py 并重新启动了我的网络服务器(nginx).但消毒剂仍在包装它以避免 html 插入.

I did edit the settings.py in my project like that and restarted my webserver (nginx). But the sanitizer is still wrapping it to avoid html-insertion.

我想避免为此目的编写 SoundCloud 插件.

I would like to avoid writing a SoundCloud plugin only for this purpose.

欢迎提出任何建议.

推荐答案

正如@yakky 在评论中所建议的,我确实在 2.8.1 版中更新了 Django 环境以使用djangocms_text_ckeditor".

As suggested by @yakky in the comments I did update the Django environment to use "djangocms_text_ckeditor" in version 2.8.1.

在我的 settings.py 中使用此设置时,效果很好:

While using this settings in my settings.py, it works great:

TEXT_ADDITIONAL_TAGS = ('iframe',)
TEXT_ADDITIONAL_ATTRIBUTES = ('scrolling', 'allowfullscreen', 'frameborder', 'src', 'height', 'width')

(soundcloud)iframe 出现并且没有发生进一步的问题.

The (soundcloud) iframe shows up and no further problems did occur.

请注意:更新您的环境可能会导致失败.始终首先在开发环境中尝试.

Be aware: Updating your environment can cause failures. Always try first within a development environment.

这篇关于如何在 django-cms 中使用 iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆