• 如何在django项目中使用django-ckeditor


    1、安装

      pip install django-ckeditor

    2、安装Pillow

      Pillow是python的一个图像处理库,django-ckeditor需要依赖该库。最简单的安装方法,当然是使用pip,假设你装过pip,可以直接运行以下命令安装:

      pip install pillow

    3、配置Django

      1、在settings.py文件中,将ckeditor、ckeditor_uploader添加到INATALLED_APPS中。

      2、在settings.py文件中,添加CKEDITOR_UPLOAD_PATH配置项。

        CKEDITOR_UPLOAD_PATH = "article_images"

    4、使用CKeditor

      from django.db import models

      from ckeditor.fields import RichTextField

      # Create your models here.

      class Goods(models.Model):
        content = RichTextField(verbose_name="商品详情")

      启动应用,富文本编辑器效果如下图所示:


      如果感觉可以用的工具比较少,那么可以在settings里增加如下配置即可。

      # 配置CKeditor
      CKEDITOR_CONFIGS = {
        'default': {
          'toolbar': (
            ['div', 'Source', '-', 'Save', 'NewPage', 'Preview', '-', 'Templates'],
            ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Print', 'SpellChecker', 'Scayt'],
            ['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'],
          ),
        }
      }

      现在一个完美的富文本输入框就完成了!!!

  • 相关阅读:
    MySQL Execution Plan--合理利用隐式的业务逻辑
    MySQL Table--MySQL外键
    MySQL倒序索引测试2
    MySQL倒序索引测试1
    CCNA-3.硬件介质
    CCNA-2.OSI 7层网络模型
    CCNA-1.认识网络
    windows本地安装Oracle数据库
    扫码登录实现原理
    phpunit 单元测试
  • 原文地址:https://www.cnblogs.com/Nxx-clara/p/11084720.html
Copyright © 2020-2023  润新知