目前用的比较多的富文本插件有百度的ueditor、ckeditor、kindeditor等,其中ueditor和kindeditor比较美观,ckeditor的皮肤较少。但是ueditor加载较慢,kindeditor样式与django后台样式相冲突,ckeditor与django耦合较好且配置简单,所以最终选择ckeditor。
下面是在django前后台中使用ckeditor的安装步骤:
一、pip install django-ckeditor
二、将‘ckeditor’和’ckeditor_uploader’加入到settings.py中的INSTALLED_APPS中
三、设定STATIC_ROOT,STATIC_ROOT = os.path.join(BASE_DIR,'static/')
,执行python manage.py collectstatic
四、文件上传设置
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media/')
CKEDITOR_UPLOAD_PATH = 'uploads/'
五、url(r'^ckeditor/', include('ckeditor_uploader.urls')),
六、CKEDITOR_IMAGE_BACKEND = "pillow"
七、配置URL
urlpatterns = [
...,
url(r'^ckeditor/', include('ckeditor_uploader.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
注意一定要加"static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)",否则提示找不到静态文件。