无法在django-ckeditor中配置youtube插件

时间:2019-03-13 10:26:47

标签: django ckeditor

我在设置和模型中完成了以下操作:

settings.py

CKEDITOR_CONFIGS = {
    'special': {
        'toolbar': 'Special',
        'toolbar_Special': [
            ['Styles', 'Format', 'Bold', 'Italic', 'Underline', 'Strike', 'SpellChecker', 'Undo'],
            ['Link', 'Unlink', 'Anchor'],
            ['Image', 'Flash', 'Table', 'HorizontalRule'],
            ['TextColor', 'BGColor'],
            ['Smiley', 'SpecialChar'], ['Source'],
        ],
        'extraPlugins': 'youtube',
    }
}

models.py

class Post(models.Model):
    user    = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE,null=True,blank=True)
    post    = RichTextUploadingField(blank=True, null=True,
                                      config_name='special',
                                      external_plugin_resources=[(
                                          'youtube',
                                          '/static/ckeditor/ckeditor/plugins/youtube_2.1.13/youtube/',
                                          'plugin.js',
                                          )],
                                      )
    date    = models.DateTimeField(auto_now_add=True)

我想在ckeditor中添加youtube插件。我已经从https://ckeditor.com/cke4/addon/youtube下载了它。

有人可以在我的代码中找到问题吗?

谢谢

1 个答案:

答案 0 :(得分:1)

您添加了

config.extraPlugins = 'youtube';

config.js 文件中?

您是否已在settings.py中配置了静态文件?

STATIC_URL = '/static/'
STATIC_ROOT = '/static/'

也请观看此视频,它可能会对您有所帮助。 https://www.youtube.com/watch?v=L6y6cn1XUfw

CKEDITOR_CONFIGS = {
'default': {
    'toolbar': 'CMS',
    'toolbar_CMS': [
        {
            'name': 'basicstyles',
            'groups': ['basicstyles', 'cleanup'],
            'items': ['Bold', 'Italic', 'Underline', '-', 'RemoveFormat']
        },
        {
            'name': 'paragraph',
            'groups': ['list', 'indent', 'blocks'],
            'items': ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote']
        },
        {
            'name': 'links',
            'items': ['Link', 'Unlink']
        },
        {
            'name': 'insert',
            'items': ['Image', 'HorizontalRule', 'Table', 'Iframe', ]
        },
        {
            'name': 'colors',
            'items': ['TextColor', 'BGColor']
        },
        {
            'name': 'youtube',
            'items': ['Youtube',]
        }
    ],
    'height': 400,
    'width': '100%',
    'allowedContent': True,
    'uiColor': '#f0f0f0',
    'extraPlugins': 'link,iframe,colorbutton,autogrow,youtube',
    'autoGrow_maxHeight': 800,
    'autoGrow_minHeight': 400,
    'removePlugins': 'resize',
    'removeButtons': None,
},
}

请确保在项目中使用大写字母

然后检查How can I install plugin into CkEditor, Django