简介

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

主要特点

  • 快速:体积小,加载速度快
  • 开源:开放源代码,高水平,高品质
  • 底层:内置自定义 DOM 类库,精确操作 DOM
  • 扩展:基于插件的设计,所有功能都是插件,可根据需求增减功能
  • 风格:修改编辑器风格非常容易,只需修改一个 CSS 文件
  • 兼容:支持大部分主流浏览器,比如 IE、Firefox、Safari、Chrome、Opera

  网址 http://kindeditor.net/doc.php

1.导入使用

<textarea name="content" id="sssssssssssssssssssssssssssssssssssssssssssssssssss" cols="30" rows="10">
<script charset="utf-8" src="/static/kindeditor-4.1.11-zh-CN/kindeditor/kindeditor-all.js"></script>
<script>
KindEditor.ready(function (K) {
window.editor = K.create(('#sssssssssssssssssssssssssssssssssssssssssssssssssss'), {
//编辑器配置
width: '100%',
height: '500px',
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', 'link', 'unlink', '|', 'about'
],
//宽高固定
resizeType:0,
//上传图片,uploadJson 指的是上传的路径,也就是咱们的路由
uploadJson : '/file_img/',
//上传图片、Flash、视音频、文件时,支持添加别的参数一并传到服务器
extraFileUploadParams :{
'csrfmiddlewaretoken':'{{ csrf_token }}'},
//指定上传文件的名字
filePostName:'myfile',
}); });
</script>

2.上传文件/数据使用

1.图片

#上传图片举例
#路由
url(r"file_img/",file_img)
#存图片
def file_img(request):
#取文件对象 文件后缀名
img = request.FILES.get ('myfile')
houzui=img.name.split('.')[-1] import os
from day1130 import settings
import hashlib
import time
#hashlib文件存储去重
h = hashlib.md5 ()
h.update (bytes (img.name, encoding='utf-8'))
h.update (bytes (time.strftime('%Y-%m-%d'), encoding='utf-8'))
name = h.hexdigest ()+'.'+houzui
path = os.path.join (settings.BASE_DIR, 'media', 'img')
#判断路径是否存在
if not os.path.exists (path):
os.mkdir (path)
path=os.path.join(path,name)
print(path)
#保存
with open(path,'wb')as f:
for i in img:
f.write(i)
#文档规定 返回一个这样形式的字典
dic = {
"error": 0,
#图片的一个访问路径 src=''
"url": "/media/img/%s" % name
}
return JsonResponse (dic)

2.数据

#发布文章举例 重点 BeautifulSoup4模块安装,使用

def add_wenzhang(request):
if request.method == 'GET':
blog = request.user.blog
return render (request, 'add_wenzhang.html', locals ())
elif request.method == 'POST':
'''
用一个模块:BeautifulSoup4---bs4---做爬虫,解析html页面
-安装
-使用 导入 from bs4 import BeautifulSoup
:param request:
:return:
'''
title = request.POST.get ('title')
content = request.POST.get ('content')
from bs4 import BeautifulSoup
# 解析html文本 防xss脚本注入攻击主要是<script></sccript>标签
soup = BeautifulSoup (content, 'html.parser')
# 简介:这里取 纯文本1到100字符充数
desc = soup.text[1:100]
# soup.find_all ()所有标签对象
for tag in soup.find_all ():
if tag.name == 'script':
# 重点 xss攻击 删除<script></sccript>标签
tag.decompose ()
# 没处理的html文本
print (content)
# 对象 str()转html文本 存数据库
print (type (soup))
models.Wenzhang.objects.create (title=title, desc=desc, blog=request.user.blog, content=str (soup))
return redirect ('/guanli/')

3.文章修改

视图

def update_wen1(request):
if request.method=='GET':
wen_id=request.GET.get('id')
content=models.Wen_zhang.objects.filter(id=wen_id).first().content
return JsonResponse({'content':content})

模板

   <form action="/update_wen1/?id={{ wen.id }}" class="form-group" method="post">
{% csrf_token %}
<p>添加文章</p>
<label for="name">标题</label><input type="text" id="name" name="title" class="form-control"
value="{{ wen.title }}">
<p><textarea id="editor_id" name="content">{{ wen.content }}</textarea></p>
<input type="submit" class="btn" value="提交">
</form> <script charset="utf-8" src="/statics/kindeditor/kindeditor-all.js"></script>
<script>
KindEditor.ready(function (K) {
window.editor = K.create(('#editor_id'), {
width: '100%',
height: '500px',
resizeType: 0,
uploadJson: '/file_img/',
{#上传图片、Flash、视音频、文件时,支持添加别的参数一并传到服务器。#}
extraFileUploadParams: {
'csrfmiddlewaretoken': '{{ csrf_token }}'
},
{#指定上传文件的名字#}
filePostName: 'myfile',
});
});
window.onload(function () {
// 取得HTML内容
alert(1)
$.ajax({
url: '/update_wen1/?id={{ wen.id }}',
type: 'get',
success(data) {
html = editor.html(data.content);
}
})
}) </script>

随机推荐

  1. MySQL数据库权限体系介绍

    本文主要向大家介绍了MySQL数据库权限体系,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助. 一.权限体系简介: MySQL的权限体系在实现上比较简单,相关权限信息主要存储在mys ...

  2. 【1】【leetcode-77】 组合

    (典型,做过似曾相识但不熟悉,基本知道怎么做但调试了一个多小时各种错) 给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合. 示例: 输入: n = 4, k = 2 输出: ...

  3. 使用sort函数进行排序

    介绍 C++的一个重要组成部分STL(Standard Template Library),即标准模板库,是一些高级数据结构和算法的集合:高级数据结构(容器)主要包括list.set.vector.m ...

  4. python中print和input的底层实现

    print print的底层通过sys.stdout.write() 实现 import sys print('hello') print('world') print(520) sys.stdout ...

  5. 新SQL temp

    select a.createtime, -- 日期 dept.name as deptName, -- 科室 (select t.docname from ( SELECT u.clinic_id ...

  6. JS创建对象之原型模式

    一.原型对象 只要创建了一个新函数,就会根据一组特定的规则为该函数创建一个prototype属性,这个属性指向函数的原型对象:在默认情况下,所有原型对象都会 自动获得一个constructor(构造函 ...

  7. 对xml进行数据查询时发生NoClassDefFoundError,dom4j和jaxen

    xml可扩展标记语言,标准通用标记语言的子集,是一种用于标记电子文件使其具有结构性的标记语言. 在web中,今天我本想测试一下用xml做为数据库存储用户信息,但是在查询用户信息的时候一直发生: jav ...

  8. 关于JDBC技术中,调用MySQL中不建议在没有服务器身份验证的情况下建立SSL连接错误解决

    今天学习到了JBDC前沿:对JDBC编写步骤的封装,出现了一大串红色报错(当然,也不能叫报错,毕竟不是所有的红色都是错误eeror,) 错误如下: Establishing SSL connectio ...

  9. 利用PHP+MySql+Ajax操作实现年月日联动功能

    PHP+MySql+Ajax实现年月日的三级联动 <!DOCTYPE html><html>    <head>        <meta charset=& ...

  10. VS中ipch文件夹和sdf文件的处理方式

    ipch文件夹和sdf是VS产生的预编译头文件和智能提示信息,对编码没有影响,可存放在固定的位置,定期进行清理