Skip to main content

用于 django labtrendig 到 s3 的 CKEditor 5。

项目描述

Django CKEditor 5

CKEditor 5 for Django >= 2.0

快速开始

.. 代码块:: bash

    pip install django-ckeditor-5

*** S3

AWS_STORAGE_BUCKET_NAME AWS_PUBLIC_MEDIA_LOCATION

  1. 将“django_ckeditor_5”添加到您的 INSTALLED_APPS 设置中,如下所示:

.. 代码块:: python

    INSTALLED_APPS = [
        ...
        'django_ckeditor_5',
    ]
  1. 在您的项目 urls.py 中包含应用程序 URLconf,如下所示:

.. 代码块:: python

   urlpatterns += [ 
       path("ckeditor5/", include('django_ckeditor_5.urls')),
   ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  1. 添加到您的 settings.py 中:

.. 代码块:: python

  STATIC_URL = '/static/'
  MEDIA_URL = '/media/'
  MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

  customColorPalette = [
        {
            'color': 'hsl(4, 90%, 58%)',
            'label': 'Red'
        },
        {
            'color': 'hsl(340, 82%, 52%)',
            'label': 'Pink'
        },
        {
            'color': 'hsl(291, 64%, 42%)',
            'label': 'Purple'
        },
        {
            'color': 'hsl(262, 52%, 47%)',
            'label': 'Deep Purple'
        },
        {
            'color': 'hsl(231, 48%, 48%)',
            'label': 'Indigo'
        },
        {
            'color': 'hsl(207, 90%, 54%)',
            'label': 'Blue'
        },
    ]

  CKEDITOR_5_CUSTOM_CSS = 'path_to.css' # optional
  CKEDITOR_5_CONFIGS = { 
    'default': {
        'toolbar': ['heading', '|', 'bold', 'italic', 'link',
                    'bulletedList', 'numberedList', 'blockQuote', 'imageUpload', ],

    },
    'extends': {
        'blockToolbar': [
            'paragraph', 'heading1', 'heading2', 'heading3',
            '|',
            'bulletedList', 'numberedList',
            '|',
            'blockQuote', 'imageUpload'
        ],
        'toolbar': ['heading', '|', 'outdent', 'indent', '|', 'bold', 'italic', 'link', 'underline', 'strikethrough',
        'code','subscript', 'superscript', 'highlight', '|', 'codeBlock',
                    'bulletedList', 'numberedList', 'todoList', '|',  'blockQuote', 'imageUpload', '|',
                    'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', 'mediaEmbed', 'removeFormat',
                    'insertTable',],
        'image': {
            'toolbar': ['imageTextAlternative', 'imageTitle', '|', 'imageStyle:alignLeft', 'imageStyle:full',
                        'imageStyle:alignRight', 'imageStyle:alignCenter', 'imageStyle:side',  '|'],
            'styles': [
                'full',
                'side',
                'alignLeft',
                'alignRight',
                'alignCenter',
            ]

        },
        'table': {
            'contentToolbar': [ 'tableColumn', 'tableRow', 'mergeTableCells',
            'tableProperties', 'tableCellProperties' ],
            'tableProperties': {
                'borderColors': customColorPalette,
                'backgroundColors': customColorPalette
            },
            'tableCellProperties': {
                'borderColors': customColorPalette,
                'backgroundColors': customColorPalette
            }
        },
        'heading' : {
            'options': [
                { 'model': 'paragraph', 'title': 'Paragraph', 'class': 'ck-heading_paragraph' },
                { 'model': 'heading1', 'view': 'h1', 'title': 'Heading 1', 'class': 'ck-heading_heading1' },
                { 'model': 'heading2', 'view': 'h2', 'title': 'Heading 2', 'class': 'ck-heading_heading2' },
                { 'model': 'heading3', 'view': 'h3', 'title': 'Heading 3', 'class': 'ck-heading_heading3' }
            ]
        }
    }
}
  1. 添加到您的models.py

.. 代码块:: python

    from django.db import models
    from django_ckeditor_5.fields import CKEditor5Field
    
    
    class Article(models.Model):
        title=models.CharField('Title', max_length=200)
        text=CKEditor5Field('Text', config_name='extends')

包括以下 ckeditor5 插件:

        Essentials,
        UploadAdapter,
        Autoformat,
        Bold,
        Italic,
        Underline,
        Strikethrough, Code, Subscript, Superscript,
        BlockQuote,
        Heading,
        Image,
        ImageCaption,
        ImageStyle,
        ImageToolbar,
        ImageUpload,
        ImageResize,
        Link,
        List,
        Paragraph,
        Alignment,
        Font,
        PasteFromOffice,
        SimpleUploadAdapter,
        MediaEmbed,
        RemoveFormat,
        Table, TableToolbar,
        TableProperties, TableCellProperties,
        Indent, IndentBlock,
        Highlight,
        TodoList,
        ImageTitle

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

ckeditor5_trendig-0.6.2.tar.gz (1.4 MB 查看哈希

已上传 source

内置分布

ckeditor5_trendig-0.6.2-py3-none-any.whl (1.4 MB 查看哈希

已上传 py3