【问题标题】:Django CKEditor - youtube embeded video disappear after saving at admin panelDjango CKEditor - youtube 嵌入视频在管理面板保存后消失
【发布时间】:2022-02-22 22:15:49
【问题描述】:

上传没有问题。但是当我查找文章进行编辑时,我看不到 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 源代码”并保存文章时,甚至当前视频也会从数据库中删除

【问题讨论】:

  • 您是否以某种方式解决了这个问题?
  • @1D0BE 很遗憾没有

标签: django django-admin ckeditor django-ckeditor


【解决方案1】:

在自己尝试了一下之后,我得到了here描述的答案。

在你的配置中加入这个:

config.extraAllowedContent = 'iframe[*]'

它允许在您的编辑器中使用 iframe-tags。

【讨论】:

  • 我已经完成了没有 youtube 扩展的项目,但我以后会尝试这种方法。感谢您的回复
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-20
  • 2012-08-24
  • 2017-03-05
  • 2016-01-24
  • 1970-01-01
  • 2012-03-14
  • 2021-12-04
相关资源
最近更新 更多