Django CKEditor - youtube 嵌入的视频在管理面板保存后消失

问题描述 投票:0回答:3

上传没有问题。但是当我查找文章进行编辑时,我看不到 youtube 视频

保存前:

保存后:

但实际上 iframe 块在那里。问题是我再也看不到管理面板了

settings.py

CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': 'CMS',
        'width': '100%',
        'toolbar_CMS': [
            ['Format', 'Styles', 'FontSize'],
            [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript'],
            ['TextColor', 'BGColor'],
            ['Link', 'Unlink'],
            ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
            ['Undo', 'Redo'],
            ['Copy', 'Paste', 'PasteText', 'PasteFromWord'],
            ['SelectAll', 'Find', 'Replace'],
            ['NumberedList', 'BulletedList'],
            ['Outdent', 'Indent'],
            ['Smiley', 'SpecialChar', 'Blockquote', 'HorizontalRule'],
            ['Table', 'Image', 'Youtube'],
            ['ShowBlocks', 'Source', 'About']
            
        ],
        'extraPlugins': 'youtube',
        'contentsCss': (
            '/staticfiles/ckeditor/customization-files/style.css',
            '/staticfiles/ckeditor/customization-files/bootstrap.css',
        ),
    },
}

CKEDITOR_UPLOAD_PATH = 'content/ckeditor/'

models.py

class Article(models.Model):
    title = models.CharField(max_length=200)
    content = RichTextField(
        extra_plugins=['youtube'],
        null = False,
        blank=False,
        external_plugin_resources=[(
            'youtube',
            '/staticfiles/ckeditor/extra_plugins/youtube/',
            'plugin.js',
        )],
        )
    updated = models.DateField(auto_now=True)
    created = models.DateField(auto_now_add=True)

Django 版本:3.2.3 django-ckeditor 版本:6.1.0

额外的细节:当我点击“查看 HTML 源代码”并保存文章时,甚至当前的视频也会从数据库中删除

django django-admin ckeditor django-ckeditor
3个回答
0
投票

在自己尝试了一下之后,我得出了这里描述的答案.

在您的配置中包括这个:

config.extraAllowedContent = 'iframe[*]'

它允许在您的编辑器中使用 iframe 标签。


0
投票

基于这个评论,我补充了

"removePlugins": ["stylesheetparser", "iframe"],

进入 settings.py 中我的 CKEDITOR_CONFIGS = {} 中的“默认”部分

此修改后,在按下“保存”按钮并关闭并重新打开包含 CKEditor 的选项卡后,所有嵌入视频在管理面板的 CKEditor 中可见


0
投票

就我而言,这是由于缺少配置引起的。

我的配置如下:

'extraPlugins': ','.join([
            ...
            'autoembed',
            'embedsemantic',
            ...
        ]),
        'embed_provider': '//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}&api_key=' + IFRAMELY_API_KEY,

当我点击

Save
按钮时,存储在数据库中的内容不包括
iframe
标签:

<oembed>https://www.youtube.com/watch?v=F6oi-J740kk</oembed>\r+

所以我的解决方案是在配置中启用

embedbase
embed
插件:

'extraPlugins': ','.join([
            ...
            'autoembed',
            'embedsemantic',
            'embedbase', //<---This
            'embed',     //<---This
            ...
        ]),
        'embed_provider': '//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}&api_key=' + IFRAMELY_API_KEY,
        'extraAllowedContent': 'iframe[*]', // <--- Fixes disappearing issue

之后数据库中的内容包含iframe标签:

<div style="height:0; left:0; padding-bottom:56.25%; position:relative;
 width:100%"><iframe allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share;" allowfullscreen="" scrolling="no" src
="https://www.youtube.com/embed/F6oi-J740kk?rel=0" style="top: 0; left: 0; width: 100%; height: 100%; position: absolute; border: 0;"></iframe></div>\r
© www.soinside.com 2019 - 2024. All rights reserved.