首页 > 解决方案 > Django-ckeditor 的内容在管理页面中没有被设置为 html 样式

问题描述

我正在使用django-ckeditor 5.8.0with python3.6, django 2.2.5onubuntu 18.04.3

settings.py

CKEDITOR_CONFIGS = {
    'default': {
        'skin': 'moono',
        'width': '100%',
        'toolbar_Basic': [
            ['Source', '-', 'Bold', 'Italic']
        ],
            {'name': 'paragraph',
             'items': ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-',
                       'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl',
                       'Language']},
            {'name': 'links', 'items': ['Link', 'Unlink', 'Anchor']},
            {'name': 'insert',
             'items': ['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak', 'Iframe']},
            '/',
            {'name': 'styles', 'items': [
                'Styles', 'Format', 'Font', 'FontSize']},
            '/',
            {'name': 'yourcustomtools', 'items': [
                'CodeSnippet',
            ]},
        ],
        'toolbar': 'YourCustomToolbarConfig',
        'tabSpaces': 4,
        'extraPlugins': ','.join([
            'uploadimage',
            'codesnippet',
        ]),
    }
}

models

content = RichTextUploadingField()

CKEditor 的static文件以adminmode 提供,但cssfile( contents.css) 不会在其他views地方加载。

我正在使用ManifestStaticFilesStorage并且在运行之后collectstatic,文件存在于它应该存在的地方。

我还在以下行中添加了template

<script>window.CKEDITOR_BASEPATH = "{% static '/ckeditor/ckeditor/' %}";</script>
<script type="text/javascript" src="{% static 'ckeditor/ckeditor-init.js' %}" data-ckeditor-basepath="{% static 'ckeditor/ckeditor/' %}" id="ckeditor-init-script"></script>
<script type="text/javascript" src="{% static 'ckeditor/ckeditor/ckeditor.js' %}"></script>

***

{{content|safe}}

这是html来自浏览器的图像:

图片

单击这两个js文件也会显示其内容,这意味着它们是可访问的。

contents.css文件未加载,因此没有样式。

同样的故事development server

任何解决问题的建议都会很棒。

标签: htmldjangockeditordjango-ckeditor

解决方案


推荐阅读