【问题标题】:Django Ckeditor: How to change background color/stylingDjango Ckeditor:如何更改背景颜色/样式
【发布时间】:2021-06-11 09:19:12
【问题描述】:

我无法更改富文本编辑器的背景颜色。大多数地方都说要编辑ckeditor css文件,但这不在我的django项目中,因为我认为我正在这样做。有没有办法在设置配置中更改它/添加样式?还是有更好的方法来做到这一点?

模板:

<script type="text/javascript" src="ckeditor.js">
    window.CKEDITOR_BASEPATH = '/static/ckeditor/ckeditor/';
    CKEDITOR.replace( 'links' );
    
</script>

设置文件:

CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': 'Custom',
        'toolbar_Custom': [
             ['Link', 'Unlink'],
        ],
        'height': 200,
        'width': 750,
    
        'stylesSet': [
            {
                "name": 'Lead',
                "element": 'p',
                "attributes": {"margin-top": "10px"},


            },
    
        ],
    }
}

【问题讨论】:

    标签: django django-forms ckeditor django-ckeditor


    【解决方案1】:

    如果你想在 ck 编辑器中添加自定义样式和自定义类属性,如果你在 Django 管理站点使用 CKEditor 可以试试这个,而不是你必须添加这个在你的

    your_env/lib/python3.8/site-packages/ckeditor/static/ckeditor/ckeditor/config.js
    

    config.js 内你必须替换它

    CKEDITOR.editorConfig = function( config ) {
        config.allowedContent = true;
        config.removeFormatAttributes = '';
    };
    

    并且您使用的是自定义管理面板,而不是添加您想要使用 CKEditor

    的位置
    <script>
        CKEDITOR.replace('editor1');
        CKEDITOR.config.allowedContent = true;
        CKEDITOR.config.removeFormatAttributes = '';
    </script>
    

    注意:如果您没有任何输出,请先运行 collectstatic 命令,然后再进行硬刷新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-13
      • 2015-02-06
      • 2011-11-11
      • 1970-01-01
      • 2023-03-15
      • 2021-08-31
      相关资源
      最近更新 更多