KindEditor 是一套开源的在线HTML编辑器,主要用于让用户在网站上获得所见即所得编辑效果,开发人员可以用 KindEditor 把传统的多行文本输入框(textarea)替换为可视化的富文本输入框。 KindEditor 使用 JavaScript 编写,可以无缝地与 Java、.NET、PHP、ASP 等程序集成,比较适合在 CMS、商城、论坛、博客、Wiki、电子邮件等互联网应用上使用。

http://kindeditor.net/doc.php

一、编辑器使用方法

1. 下载编辑器

下载 KindEditor 最新版本,下载之后打开 examples/index.html 就可以看到演示。

下载页面: http://www.kindsoft.net/down.php

2. 部署编辑器

解压 kindeditor-x.x.x.zip 文件,将所有文件上传到您的网站程序目录里,例如:http://您的域名/editor/

Note

您可以根据需求删除以下目录后上传到服务器。

asp - ASP程序
asp.net - ASP.NET程序
php - PHP程序
jsp - JSP程序
examples - 演示文件

3. 修改HTML页面

  1. 在需要显示编辑器的位置添加textarea输入框。
<textarea id="editor_id" name="content" style="width:700px;height:300px;">
&lt;strong&gt;HTML内容&lt;/strong&gt;
</textarea>
  1. 在该HTML页面添加以下脚本。
<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>

二、在博客中使用

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
margin: 0;
}
.header{
height: 50px;
background-color: #2e6da4;
line-height: 50px;
color: white;
}
.header span{
margin-left: 50px;
font-size: 25px;
}
.add_body{
width: 80%;
margin: 0 auto;
}
#artical_title{
width: 300px;
}
</style>
<link rel="stylesheet" href="/static/bootstrap-3.3.7-dist/css/bootstrap.css"> </head>
<body>
<div class="header">
<span>博客后台</span>
</div> <div class="add_body">
<h1>文章添加</h1>
<label for="artical_title">添加文章:</label> <div>
<form method="post" action="">
{% csrf_token %}
<input id="artical_title" name="artical_title" class="form-control" type="text">
<p><label for="artical_content">文章内容</label></p>
<textarea id="artical_content" name="artical_content" style="width:700px;height:300px;">
&lt;strong&gt;HTML内容&lt;/strong&gt;
</textarea>
<p><input type="submit" class="btn btn-info" value="提交"></p>
</form>
</div>
</div> <script charset="utf-8" src="/static/kindeditor/kindeditor-all.js"></script>
<script charset="utf-8" src="/static/kindeditor/lang/zh-CN.js"></script>
<script src="/static/bootstrap-3.3.7-dist/js/jquery-1.12.4.js"></script>
<script> KindEditor.ready(function(K) {
window.editor = K.create('#artical_content', { //这里定义需要对哪个textarea进行装饰
resizeType:0,
uploadJson:"/blog/backend/upload/", //定义文件的上传路由
extraFileUploadParams:{
csrfmiddlewaretoken:$("[name='csrfmiddlewaretoken']").val()
},
filePostName:"upload_img", //定义上传后的文件"name"属性名称,便于后台request获取
});
});
</script>
</body>
</html>

add_artical.html

def add_artical(request, username):
if request.method == "POST":
user = request.user
artical_title = request.POST.get("artical_title")
artical_content = request.POST.get("artical_content")
# desc = artical_content[0:150] # 解释html标签
from bs4 import BeautifulSoup
# html.parser为解析器,是python标准库
bs = BeautifulSoup(artical_content, "html.parser")
desc = bs.text[0:150] + "..." # 过滤非法标签
for tag in bs.find_all():
if tag.name in ["script", "link"]:
# 将该非法标签从对象中移除
tag.decompose() # 打印结果为"123 <class 'bs4.BeautifulSoup'>"
print(bs,type(bs)) try:
artical_obj = models.Artical.objects.create(user=user, desc=desc, title=artical_title)
models.ArticalDetail.objects.create(content=str(bs), artical=artical_obj)
except:
return HttpResponse("更新文章失败 ")
return HttpResponse("添加成功") return render(request, "add_artical.html") from Hero import settings
import os, json
def upload(request):
obj = request.FILES.get("upload_img")
# print("name", obj.name) path = os.path.join(settings.MEDIA_ROOT, "add_artical_img", obj.name) with open(path, "wb") as f:
for line in obj:
f.write(line) res = {
"error": 0,
"url": "/media/add_artical_img/" + obj.name
} return HttpResponse(json.dumps(res))

views.py

re_path('backend/add_artical/(?P<username>\w+)', views.add_artical),
path('backend/upload/', views.upload),

urls.py

 

KindEditor的使用的更多相关文章

  1. 让kindeditor显示高亮代码

    kindeditor4.x代码高亮功能默认使用的是prettify插件,prettify是Google提供的一款源代码语法高亮着色器,它提供一种简单的形式来着色HTML页面上的程序代码,实现方式如下: ...

  2. Kindeditor在ThinkPHP框架下的使用

    1.简单调用Kindeditor的图片上传功能: a.Html部署图片预览,记录图片上传成功之后的路径,以及上传图片点击按钮 <tr> <td>活动图片:</td> ...

  3. ASP.NET MVC5+EF6+EasyUI 后台管理系统(36)-文章发布系统③-kindeditor使用

    系列目录 我相信目前国内富文本编辑器中KindEditor 属于前列,详细的中文帮助文档,简单的加载方式,可以定制的轻量级.都是系统的首选 很多文章教程有kindeditor的使用,但本文比较特别可能 ...

  4. KindEditor 给KindEditor赋值

    在项目的过程中,使用了KindEditor编辑器,然后在赋值的时候,我的编辑器ID是content,然后我想通过$("#content").html()来赋值,发现赋值失败,后来百 ...

  5. Ajax 提交KindEditor的数据

    这次我是在EasyUI中使用了KindEditor的编辑器,按照官方给的代码,总是无法获取编辑器里面的值(内容),如下:         KindEditor.ready(function (K) { ...

  6. 如何在一个页面添加多个不同的kindeditor编辑器

    kindeditor官方下载地址:http://kindeditor.net/down.php    (入门必看)kindeditor官方文档:http://kindeditor.net/doc.ph ...

  7. kindeditor 去掉网络图片上传功能

    kindeditor是一款开源的富文本编辑器,其内容设置均为可配置,使用比较灵活. 去掉网络图片的页面:allowImageRemote: false, 修改上传的图片的name:filePostNa ...

  8. 关于JqueryEasyUI集合Kindeditor

    写在前面 上一篇<初试JqueryEasyUI(附Demo)>: 在上一篇说过,下面要试下easyui集合编辑器,关于编辑器网上有很多,ckeditor.ueditor.kindedito ...

  9. jquery弹出下拉列表插件(实现kindeditor的@功能)

    这几天有个工作需求,就是在富文本输入区域(kindeditor)可以有@功能,能够容易提示用户名的(像在qq群组@人一样).在网上找了一个叫bootstrap-suggest的插件,却不能满足我的需求 ...

  10. kindeditor在光标处插入编辑器外的数据

    页面 <div class="form-group clearfix"> <label class="control-label col-sm-3 co ...

随机推荐

  1. Cascade属性的取值

    Cascade属性的取值有:1.none:忽略其他关联的对象,默认值.2.save-update:当session通过save(),update(),saveOrUpdate()方法来保存或更新对象时 ...

  2. Yii框架操作数据库的几种方式与mysql_escape_string

    一.Yii操作数据库的几种选择 1,PDO方式. $sql = "";//原生态sql语句 xx::model()->dbConnection->createComma ...

  3. 跟我学算法-吴恩达老师的logsitic回归

    logistics回归是一种二分类问题,采用的激活函数是sigmoid函数,使得输出值转换为(0,1)之间的概率 A = sigmoid(np.dot(w.T, X) + b ) 表示预测函数 dz ...

  4. inotify监测实例

    /************************************************************************* > File Name: inotify.c ...

  5. 在 springboot 中如何整合 shiro 应用 ?

     Shiro是Apache下的一个开源项目,我们称之为Apache Shiro. 它是一个很易用与Java项目的的安全框架,提供了认证.授权.加密.会话管理,与spring Security 一样都是 ...

  6. Linux基石【第一篇】VMware上安装Centos及配置

    一.安装VMware软件 首先,下载个VMware软件,直接百度:VMware,然后找到可以下载的就可以 然后按步骤安装即可,安装完后,双击打开 二.安装Centos系统 打开VMware虚拟机,然后 ...

  7. IPMI总结

    http://www.chenshake.com/summary-of-ipmi/ 记忆的很清楚,2000年的时候,当时还是Compaq,推出第一款远程控制卡,当时听起来非常神奇.可以远程开机,关机, ...

  8. ubuntu 12.04安装jdk 8

    转载:http://www.itnose.net/detail/6196130.html Ubuntu12.4安装jdk1.8 1.要安装的jdk,我把它拷在了共享文件夹里面.    (用优盘拷也可以 ...

  9. React Native开源项目案例

    (六).React Native开源项目: 1.Pober Wong_17童鞋为gank.io做的纯React Native项目,开源地址:https://github.com/Bob1993/Rea ...

  10. YUI前端优化之Server篇

    二.网站Server 篇:使用内容分发网络为文件头指定Expires或Cache-ControlGzip压缩文件内容配置ETag尽早刷新输出缓冲使用GET来完成AJAX请求 11.使用内容分发网络 用 ...