kindeditor 编辑器php
博客园用的 TinyMCE 编辑器 支持拖放/粘贴上传图片css
下载 KindEditor 最新版本,下载以后打开 examples/index.html 就能够看到演示。html
下载页面: http://www.kindsoft.net/down.phpjson
解压 kindeditor-x.x.x.zip 文件,将全部文件上传到您的网站程序目录里,例如:http://您的域名/editor/浏览器
Note服务器
您能够根据需求删除如下目录后上传到服务器。asp.net
<textarea id="editor_id" name="content" style="width:700px;height:300px;"> <strong>HTML内容</strong> </textarea>
Notejsp
<script charset="utf-8" src="/editor/kindeditor.js"></script> <script charset="utf-8" src="/editor/lang/zh-CN.js"></script> <script> KindEditor.ready(function(K) { window.editor = K.create('#editor_id'); }); </script>
Note编辑器
var options = { cssPath : '/css/index.css', filterMode : true }; var editor = K.create('textarea[name="content"]', options);
// 取得HTML内容
html = editor.html(); // 同步数据后能够直接取得textarea的value editor.sync(); html = document.getElementById('editor_id').value; // 原生API html = K('#editor_id').val(); // KindEditor Node API html = $('#editor_id').val(); // jQuery // 设置HTML内容 editor.html('HTML内容');
Note函数
// 关闭过滤模式,保留全部标签
KindEditor.options.filterMode = false; KindEditor.ready(function(K)) { K.create('#editor_id'); }
调节参数参考 http://kindeditor.net/doc.php
例如:
KindEditor.ready(function(K)) { K.create('#editor_id',{
width:"800",
heigth:"600",
.....
}
); }
编辑器上传文件
指定上传文件的服务器端程序。
上传图片、Flash、视音频、文件时,支持添加别的参数一并传到服务器。
KindEditor.ready(function(K) { K.create('#id', { extraFileUploadParams : { item_id : 1000, category_id : 1 } }); });
Note
4.1.1版本开始支持。
上传文件写法
KindEditor.ready(function(K)) { K.create('#editor_id',{
uploadJson:“/upload/”, #上传文件储存路径
extraFileUploadParams : {
csrfmiddlewaretoken:$("[name='csrfmiddlewaretoken']").val()
},
filePostName:"upload_img" #知道上传文件的key值
}
def upload(request):
"""
编辑器上传文件接受视图函数
:param request:
:return:
"""
print(request.FILES)
img_obj=request.FILES.get("upload_img") #取出文件对象
print(img_obj.name)
path=os.path.join(settings.MEDIA_ROOT,"add_article_img",img_obj.name) #文件保存路径
with open(path,"wb") as f:
for line in img_obj:
f.write(line)
import jsonresponse = { 'error':0, 'url':'media/add_articel_img%s'%img_obj}# 返回图片路径,预览图片return HttpResponse(json.dumps(response))