【发布时间】: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 按钮仍然不存在。