首页 > 其他 > 详细

在django项目中使用ckeditor

时间:2020-10-27 09:59:42      阅读:22      评论:0      收藏:0      [点我收藏+]

1、安装ckeditor


pip install django-ckeditor
pip install pillow

 

2、配置

 

a,在你的settings.py文件中

INSTALLED_APPS = [
‘ckeditor‘, 
‘ckeditor_uploader‘ 
]

b,在你的settings.py文件中,添加CKEDITOR_UPLOAD_PATH配置项

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
CKEDITOR_UPLOAD_PATH = "images"

c.在settings目录中增加如下配置即可
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‘],
),
}
}

 

3、使用

 

在models.py中引用

from ckeditor.fields import RichTextField
from ckeditor_uploader.fields import RichTextUploadingField

创建模型时间:

profile = RichTextField(verbose_name=‘活动简介‘)

这样在admin中直接就可以显示了。

 

4、在模板中使用富文本编辑器

 

需要引用:
<script src="{% static ‘ckeditor/ckeditor-init.js‘ %}"></script>
<script src="{% static ‘ckeditor/ckeditor/ckeditor.js‘ %}"></script>
如果是显示富文本的内容,记得加上safe过滤器哟。

在django项目中使用ckeditor

原文:https://www.cnblogs.com/rabbie/p/13883038.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!