django-ckeditor 富文本编辑器个性化定制

ckeditor提供了个性化的定制编辑器的功能,只需要预先设定toolbar的名称,使用时直接引用即可。

在setting.py文件中加入ckeditor的相关配置,这里我预先定义两个配置名称“desc”和“body”,将来使用的时候直接引用配置名称即可。

另外还可以设置编辑器的背景色,关键字时“uiColor”。

CKEDITOR_CONFIGS = {
    'desc': {
        'toolbar':  (
            # ['div','Source','-','Save','NewPage','Preview','-','Templates'],
            ['Cut','Copy','Paste','PasteText','PasteFromWord'],
            # ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
            # ['Form','Checkbox','Radio','TextField','Textarea','Select','Button', 'ImageButton','HiddenField'],
            ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
            ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
            ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
            # ['Link','Unlink','Anchor'],
            ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
            ['Styles','Format','Font','FontSize'],
            ['TextColor','BGColor'],
            # ['Maximize','ShowBlocks','-','About', 'pbckcode'],
            ['Blockquote', 'CodeSnippet'],
            ),
        'height': 100,
        'width': 1200,
        'tabSpaces': 4,
         'extraPlugins' : 'autogrow', # 代码插件
    },
    'body': {
        # 'toolbar': "Full",
        'toolbar': (
            ['div','Source'],
            ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker','Scayt'],
            # ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
            ['Styles', 'Format', 'Font', 'FontSize'],
            ['Bold', 'Italic', 'Underline', ' Strike', '-', 'Subscript', 'Superscript'],
            ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
            ['NumberedList', 'BulletedList', '-', 'Outdent','Indent', 'Blockquote'],
            ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
            ['Link', 'Unlink', 'Anchor'],
            ['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak'],
            ['TextColor', 'BGColor'],
            ['Maximize',' ShowBlocks', '-', 'About', 'pbckcode'],
            ['Blockquote', 'CodeSnippet'],
            ),
        'height': 600,
        'width': 1200,
        'tabSpaces': 4,
        # 'uiColor': '#CCEAEE',
        'extraPlugins': 'codesnippet, autogrow',  # 代码插件
        'autoGrow_maxHeight ': 1200,
    }
}

 使用时直接根据定义好的名称直接引用即可:

content = forms.CharField(widget=CKEditorUploadingWidget(config_name='body'), label='正文', required=True)
desc = RichTextField(config_name='desc', verbose_name='摘要')

 

展示效果如下:


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值