table of Contents
table of Contents
Instructions
Directly to the input box binding event can pay attention to the introduction of js bit different way, pay more coding
<script charset="utf-8" src="/editor/kindeditor.js"></script>
<script charset="utf-8" src="/editor/lang/zh-CN.js"></script>
KindEditor.ready(function(K) {
window.editor = K.create('#editor_id');
}); //添加富文本编辑菜单栏
K.create('要绑定事件的文本输入框id',{初识化数据放在这里})
K.create two parameters, parameters to be bound tag id values, parameter 2, the initialization parameter
KindEditor.ready(function (K) {
window.editor = K.create('#editor_id',
{
width: '100%', //宽度支持%和px样式
items: [
'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
'anchor'
]
})
;
});
official website
Rich Text Editor official website http://kindeditor.net/docs/option.html#items
Examples of upload and download pictures
View deal
def up_img(request,):
img_obj = request.FILES.get("imgFile",None)
# 图片的名字默认是imgFile
path=os.path.join(settings.MEDIA_ROOT,"article_img",img_obj.name)# 拿到文件上传的路径,保存到medio文件中,方便访问
# 默认名字是imgFile
with open(path,"wb") as f:
for i in img_obj:
f.write(i)
print(path)
data={
"error":0, # 给编辑器返回上传结果
"url":"/media/article_img/"+img_obj.name # 返回图片路径,编辑器访问浏览器取数据
}
return HttpResponse(json.dumps(data))
js event
KindEditor.ready(function (K) {
window.editor = K.create('#editor_id',
{
width: '100%',
uploadJson:"/up_img/",
extraFileUploadParams:{ //相当于ajax的data
csrfmiddlewaretoken:$("[name='csrfmiddlewaretoken']").val()
}
})
;
}); //添加富文本编辑菜单栏
filePostName specify the file upload form name.
Data Type: String
Default value: imgFile
Menu bar function screening
items: [
'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
'anchor'
],