Django笔记 使用编辑器django-ckeditor

最近试了几下Django的编辑器,各有各的好处,在不使用markdown的情况下,发现ckeditor实现的比较简单,步骤如下。

基本设置

1.安装django-ckeditor

$ pip install django-ckeditor

2.在setting中,添加ckeditor , ckeditor_uploader 到INSTALLED_APPS

3.在setting中,添加

CKEDITOR_UPLOAD_PATH = "uploads/"
CKEDITOR_IMAGE_BACKEND = "pillow"
CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'

4.执行 python manage.py collectstatic ,收集静态文件

后端显示编辑器

5.model中添加ckeditor的字段

from ckeditor_uploader.fields import RichTextUploadingField
class Entry(models.Model):
    body = RichTextUploadingField() #RichTextField()

from ckeditor.fields import RichTextField
class Post(models.Model):
    content = RichTextField()

6.在admin site中可以显示。

前端添加编辑器

7.添加js文件

<script src="//cdn.ckeditor.com/4.5.9/standard/ckeditor.js">script>

8.添加代码如下


<html>
    <head>
        <meta charset="utf-8">
        <title>CKEditortitle>
        <script src="//cdn.ckeditor.com/4.5.9/standard/ckeditor.js">script>
    head>
    <body>
        <textarea name="editor1">textarea>
        <script>
            CKEDITOR.replace( 'editor1' , {uiColor: '#9AB8F3'});
        script>
    body>
html>

参照

http://docs.ckeditor.com/#!/guide/dev_configuration
https://python.web.id/blog/django-installing-django-ckeditor/
https://github.com/django-ckeditor/django-ckeditor
https://github.com/django-ckeditor/django-ckeditor#installation
http://cdn.ckeditor.com/
http://ckeditor.com/download

https://github.com/mjr27/django-flatpages-tinymce

你可能感兴趣的:(Django学习笔记)