【问题标题】:YoutubePlugin of ckeditor with Djangockeditor 的 YoutubePlugin 与 Django
【发布时间】:2018-12-13 04:21:36
【问题描述】:

实际上我正在开发一个 Django 网站,我使用 CKEditor 输入了效果很好的富文本。

但是当我尝试将youtube插件添加到ckeditor的默认设置中时,总是出现404错误说找不到js文件。不知道是设置错误还是什么。

我跟着https://github.com/django-ckeditor/django-ckeditor#installation 安装了ckeditor。并从https://ckeditor.com/cke4/addon/youtube 下载了YoutubePlugin。我将 youtube 文件夹解压缩到 /myproject/staticfiles/ckeditor/ckeditor/plugins。

这是我的设置。

STATIC_URL = '/static/'
STATIC_ROOT = 'staticfiles/'
CKEDITOR_CONFIGS = {
    'default': {
        'skin': 'moonocolor',
        'toolbar_Basic': [
            ['Source', '-', 'Bold', 'Italic']
        ],
        'toolbar_YourCustomToolbarConfig': [
            {'name': 'document', 'items': ['Source']},
            {'name': 'clipboard', 'items': ['Undo', 'Redo']},
            {'name': 'editing', 'items': ['Find', 'Replace']},
            {'name': 'basicstyles',
             'items': ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat']},
            {'name': 'paragraph',
             'items': ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', '-',
                       'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock']},
            '/',
            {'name': 'insert',
             'items': ['Image', 'Flash', 'Youtube', 'Table', 'HorizontalRule']},
            {'name': 'styles', 'items': ['Styles', 'Format', 'Font', 'FontSize']},
            {'name': 'colors', 'items': ['TextColor', 'BGColor']},
        ],
        'tabSpaces': 4,
        'height': 300,
        'width': '100%',
        'extraPlugins': 'youtube',
    },
}

还有models.py

class Post(models.Model):
    STATUS_CHOICES = (
        ('draft', 'Draft'),
        ('published', 'Published'),
    )
    title = models.CharField(max_length=250)
    slug = models.SlugField(max_length=250, unique_for_date='publish')
    author = models.ForeignKey(User, related_name='blog_posts', on_delete=models.CASCADE)
    body = RichTextUploadingField(blank=True, null=True,)
    publish = models.DateTimeField(default=timezone.now)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='draft')

    # The default manager
    objects = models.Manager()

    # Custom made manager
    published = PublishedManager()
    tags = TaggableManager()

    class Meta:
        ordering = ('-publish',)

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('blog:post_detail_view',args=[self.publish.year, self.publish.strftime('%m'), self.publish.strftime('%d'), self.slug])

还有我的文件系统

【问题讨论】:

  • 我找到了 404 的原因。因为 django 在 /bloc/static 中查找文件,因为这是一个应用程序。我将文件夹创建为 /bloc/static/ckeditor/ckeditor/plugins 并将 youtube 文件夹粘贴到其中。并且刷新后404错误消失!但在 ckeditor youtube 按钮仍然不存在。

标签: django ckeditor


【解决方案1】:

我自己的愚蠢问题。 对于 404 错误,这是因为应用程序静态文件。 Django 从应用目录中的静态文件夹中查找应用的静态文件。在我的 /blog/static 中没有 ckeditor 文件夹。使用plugins文件夹中的youtube插件将整个ckeditor文件夹复制到/blog/static中,并且已修复。

立即配置:

CKEDITOR_CONFIGS = {
    'default': {
        'skin': 'moono',
        'toolbar_Basic': [
            ['Source', '-', 'Bold', 'Italic']
        ],
        'toolbar_YourCustomToolbarConfig': [
            {'name': 'document', 'items': ['Source']},
            {'name': 'clipboard', 'items': ['Undo', 'Redo']},
            {'name': 'insert',
             'items': ['Image', 'Youtube', 'Flash', 'Table', 'HorizontalRule']},
            {'name': 'editing', 'items': ['Find', 'Replace']},
            '/',
            {'name': 'basicstyles',
             'items': ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat']},
            {'name': 'paragraph',
             'items': ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', '-',
                       'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock']},
            {'name': 'links', 'items': ['Link', 'Unlink']},
            '/',
            {'name': 'styles', 'items': ['Styles', 'Format', 'Font', 'FontSize']},
            {'name': 'colors', 'items': ['TextColor', 'BGColor']},
        ],
        'toolbar': 'YourCustomToolbarConfig',  # put selected toolbar config here
        # 'toolbarGroups': [{ 'name': 'document', 'groups': [ 'mode', 'document', 'doctools' ] }],
        'height': 420,
        'width': '100%',
        # 'filebrowserWindowHeight': 725,
        # 'filebrowserWindowWidth': 940,
        # 'toolbarCanCollapse': True,
        # 'mathJaxLib': '//cdn.mathjax.org/mathjax/2.2-latest/MathJax.js?config=TeX-AMS_HTML',
        'tabSpaces': 4,
        'extraPlugins': ','.join([
            'uploadimage', # the upload image feature
            # your extra plugins here
            'youtube',
        ]),
    }
}

【讨论】:

    猜你喜欢
    • 2022-01-23
    • 2018-01-16
    • 1970-01-01
    • 2018-01-04
    • 2018-04-06
    • 1970-01-01
    • 2016-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多