KindEditor

1、进入官网

2、下载

  官网下载:http://kindeditor.net/down.php

3、文件夹说明

├── asp                          asp示例
├── asp.net                    asp.net示例
├── attached                  空文件夹,放置关联文件attached
├── examples                 HTML示例
├── jsp                          java示例
├── kindeditor-all-min.js 全部JS(压缩)
├── kindeditor-all.js        全部JS(未压缩)
├── kindeditor-min.js      仅KindEditor JS(压缩)
├── kindeditor.js            仅KindEditor JS(未压缩)
├── lang                        支持语言
├── license.txt               License
├── php                        PHP示例
├── plugins                    KindEditor内部使用的插件
└── themes                   KindEditor主题

4、基本使用

<textarea name="content" id="content"></textarea><script src="/static/jquery-1.12.4.js"></script>
<script src="/static/plugins/kind-editor/kindeditor-all.js"></script>
<script>$(function () {initKindEditor();});function initKindEditor() {var kind = KindEditor.create('#content', {width: '100%',       // 文本框宽度(可以百分比或像素)height: '300px',     // 文本框高度(只能像素)minWidth: 200,       // 最小宽度(数字)minHeight: 400      // 最小高度(数字)});}
</script>

5、详细参数

     http://kindeditor.net/docs/option.html

6、上传文件示例

<!DOCTYPE html>
<html>
<head lang="en"><meta charset="UTF-8"><title></title>
</head>
<body><div><h1>文章内容</h1>{{ request.POST.content|safe }}
</div><form method="POST"><h1>请输入内容:</h1>{% csrf_token %}<div style="width: 500px; margin: 0 auto;"><textarea name="content" id="content"></textarea></div><input type="submit" value="提交"/>
</form><script src="/static/jquery-1.12.4.js"></script>
<script src="/static/plugins/kind-editor/kindeditor-all.js"></script>
<script>$(function () {initKindEditor();});function initKindEditor() {var a = 'kind';var kind = KindEditor.create('#content', {width: '100%',       // 文本框宽度(可以百分比或像素)
            height: '300px',     // 文本框高度(只能像素)
            minWidth: 200,       // 最小宽度(数字)
            minHeight: 400,      // 最小高度(数字)
            uploadJson: '/kind/upload_img/',extraFileUploadParams: {'csrfmiddlewaretoken': '{{ csrf_token }}'},fileManagerJson: '/kind/file_manager/',allowPreviewEmoticons: true,allowImageUpload: true});}
</script>
</body>
</html>
HTML
import os
import json
import timefrom django.shortcuts import render
from django.shortcuts import HttpResponsedef index(request):"""首页:param request::return:"""return render(request, 'index.html')def upload_img(request):"""文件上传:param request::return:"""dic = {'error': 0,'url': '/static/imgs/20130809170025.png','message': '错误了...'}return HttpResponse(json.dumps(dic))def file_manager(request):"""文件管理:param request::return:"""dic = {}root_path = '/Users/wupeiqi/PycharmProjects/editors/static/'static_root_path = '/static/'request_path = request.GET.get('path')if request_path:abs_current_dir_path = os.path.join(root_path, request_path)move_up_dir_path = os.path.dirname(request_path.rstrip('/'))dic['moveup_dir_path'] = move_up_dir_path + '/' if move_up_dir_path else move_up_dir_pathelse:abs_current_dir_path = root_pathdic['moveup_dir_path'] = ''dic['current_dir_path'] = request_pathdic['current_url'] = os.path.join(static_root_path, request_path)file_list = []for item in os.listdir(abs_current_dir_path):abs_item_path = os.path.join(abs_current_dir_path, item)a, exts = os.path.splitext(item)is_dir = os.path.isdir(abs_item_path)if is_dir:temp = {'is_dir': True,'has_file': True,'filesize': 0,'dir_path': '','is_photo': False,'filetype': '','filename': item,'datetime': time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(os.path.getctime(abs_item_path)))}else:temp = {'is_dir': False,'has_file': False,'filesize': os.stat(abs_item_path).st_size,'dir_path': '','is_photo': True if exts.lower() in ['.jpg', '.png', '.jpeg'] else False,'filetype': exts.lower().strip('.'),'filename': item,'datetime': time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(os.path.getctime(abs_item_path)))}file_list.append(temp)dic['file_list'] = file_listreturn HttpResponse(json.dumps(dic))
views

7、XSS过滤特殊标签

  处理依赖

pip3 install beautifulsoup4
from bs4 import BeautifulSoupclass XSSFilter(object):__instance = Nonedef __init__(self):# XSS白名单self.valid_tags = {"font": ['color', 'size', 'face', 'style'],'b': [],'div': [],"span": [],"table": ['border', 'cellspacing', 'cellpadding'],'th': ['colspan', 'rowspan'],'td': ['colspan', 'rowspan'],"a": ['href', 'target', 'name'],"img": ['src', 'alt', 'title'],'p': ['align'],"pre": ['class'],"hr": ['class'],'strong': []}@classmethoddef instance(cls):if not cls.__instance:obj = cls()cls.__instance = objreturn cls.__instancedef process(self, content):soup = BeautifulSoup(content, 'lxml')# 遍历所有HTML标签for tag in soup.find_all(recursive=True):# 判断标签名是否在白名单中if tag.name not in self.valid_tags:tag.hidden = Trueif tag.name not in ['html', 'body']:tag.hidden = Truetag.clear()continue# 当前标签的所有属性白名单attr_rules = self.valid_tags[tag.name]keys = list(tag.attrs.keys())for key in keys:if key not in attr_rules:del tag[key]return soup.renderContents()if __name__ == '__main__':html = """<p class="title"><b>The Dormouse's story</b></p><p class="story"><div name='root'>Once upon a time there were three little sisters; and their names were<a href="http://example.com/elsie" class="sister c1" style='color:red;background-color:green;' id="link1"><!-- Elsie --></a><a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and<a href="http://example.com/tillie" class="sister" id="link3">Tilffffffffffffflie</a>;and they lived at the bottom of a well.<script>alert(123)</script></div></p><p class="story">...</p>"""v = XSSFilter.instance().process(html)print(v)
XSS示例
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from bs4 import BeautifulSoupclass XSSFilter(object):__instance = Nonedef __init__(self):# XSS白名单self.valid_tags = {"font": ['color', 'size', 'face', 'style'],'b': [],'div': [],"span": [],"table": ['border', 'cellspacing', 'cellpadding'],'th': ['colspan', 'rowspan'],'td': ['colspan', 'rowspan'],"a": ['href', 'target', 'name'],"img": ['src', 'alt', 'title'],'p': ['align'],"pre": ['class'],"hr": ['class'],'strong': []}def __new__(cls, *args, **kwargs):"""单例模式:param cls::param args::param kwargs::return:"""if not cls.__instance:obj = object.__new__(cls, *args, **kwargs)cls.__instance = objreturn cls.__instancedef process(self, content):soup = BeautifulSoup(content, 'lxml')# 遍历所有HTML标签for tag in soup.find_all(recursive=True):# 判断标签名是否在白名单中if tag.name not in self.valid_tags:tag.hidden = Trueif tag.name not in ['html', 'body']:tag.hidden = Truetag.clear()continue# 当前标签的所有属性白名单attr_rules = self.valid_tags[tag.name]keys = list(tag.attrs.keys())for key in keys:if key not in attr_rules:del tag[key]return soup.renderContents()if __name__ == '__main__':html = """<p class="title"><b>The Dormouse's story</b></p><p class="story"><div name='root'>Once upon a time there were three little sisters; and their names were<a href="http://example.com/elsie" class="sister c1" style='color:red;background-color:green;' id="link1"><!-- Elsie --></a><a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and<a href="http://example.com/tillie" class="sister" id="link3">Tilffffffffffffflie</a>;and they lived at the bottom of a well.<script>alert(123)</script></div></p><p class="story">...</p>"""obj = XSSFilter()v = obj.process(html)print(v)
基于__new__实现单例模式示例

 

转载于:https://www.cnblogs.com/wuyongqiang/p/7218650.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/252249.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

service mysqld start,Failed to start mysqld.service: Access denied

service mysqld start 然后报&#xff1a; AUTHENTICATING FOR org.freedesktop.systemd1.manage-units Authentication is required to start mysqld.service.Authenticating as: lll,,, (lll)Password: polkit-agent-helper-1: pam_authenticate failed: Authentication fa…

使用realsense t265测试svo2.0视觉里程计

毕业三年了&#xff0c;现在是第二份工作&#xff0c;第一份工作已经结束一年半了&#xff0c;这意味着&#xff0c;我有一年半的时间没有搞视觉SLAM相关的东西了&#xff0c;虽然在第二份工作也是做视觉相关的&#xff0c;但是只是用到一些目标识别和跟踪的知识&#xff0c;并…

JSP动作标识

jsp中include有两种形式: include指令&#xff1a;<% include file""%> include动作&#xff1a;<jsp:include page"" /> 他们的区别&#xff1a; <% include file""%>又称静态包含&#xff0c;使用时要注意以下几点&#xf…

面试必问之JVM原理

1&#xff1a;什么是JVM JVM是Java Virtual Machine&#xff08;Java虚拟机&#xff09;的缩写&#xff0c;JVM是一种用于计算设备的规范&#xff0c;它是一个虚构出来的计算机&#xff0c;是通过在实际的计算机上仿真模拟各种计算机功能来实现的。Java虚拟机包括一套字节码指令…

InfluxDB学习之InfluxDB的基本操作

InfluxDB提供类SQL语法&#xff0c;如果熟悉SQL的话会非常容易上手。本文就为大家介绍一下InfluxDB的基本操作。 InfluxDB提供类SQL语法&#xff0c;如果熟悉SQL的话会非常容易上手。 一、InfluxDB操作方式 InfluxDB提供三种操作方式&#xff1a; 1&#xff09;客户端命令行方式…

运行svo 2.0的 vio时遇到opencv冲突的问题

当我运行如下指令时&#xff0c;遇到了如下问题 指令 cd svo_ws source ./devel/setup.bash roslaunch svo_ros euroc_vio_mono.launch rosbag play MH_01_easy.bag -s 50 运行时遇到的问题 OpenCV Error: Bad argument (Unknown interpolation method) in resize, file /b…

DOS Network一月项目月报

欢迎大家阅读DOS Network第一期项目月报&#xff01;DOS为了跟大家更好的沟通和交流&#xff0c;将在每个月为大家跟进DOS Network项目进展月报。月报主要分为项目研发和社区及营销两个部分。 如果你是刚认识DOS Network预言机网络的新朋友&#xff0c;欢迎查阅往期文章&#x…

lsof详解

from:https://www.cnblogs.com/the-study-of-linux/p/5501593.html lsof (list open files)是一个列出当前系统打开文件的工具。在linux系统环境下&#xff0c;任何事物都可以以文件形式存在&#xff0c;通过文件不仅可以访问常规的数据&#xff0c;还可以访问网络连接和硬件。…

Ubuntu18.04上下载安装使用sogou输入法

下载地址&#xff1a;搜狗输入法Linux官网-首页 安装设置网址&#xff1a;搜狗输入法Linux官网-安装指导 这样Ubuntu下工作就更加方便了。

正则

&#xff08;一&#xff09;字符类 [...]  方括号内的任意字符 [^...]   不在方括号内的任意字符 .    除换行符和其它Unicode行终止符之外的任意字符 \w   任何ASCII字符组成的单词&#xff0c;等价于[a-zA-Z0-9] \W   任何非ASCII字符组成的单词&#xff0c;等价…

使用Cloud Studio写python

1、进入【腾讯云开发者平台】 2、点击【进入工作空间】 3、点击【新建工作空间】 4、点击【从模版创建】 选择你需要的空间环境&#xff0c;就可以开始啦&#xff01;转载于:https://juejin.im/post/5c75f79051882562962ef5d7

显卡、显卡驱动、显存、GPU、CUDA、cuDNN

&#xfeff;&#xfeff;显卡Video card&#xff0c;Graphics card&#xff0c;又叫显示接口卡&#xff0c;是一个硬件概念&#xff08;相似的还有网卡&#xff09;&#xff0c;执行计算机到显示设备的数模信号转换任务&#xff0c;安装在计算机的主板上&#xff0c;将计算机的…

ros rviz显示rosbag中的图像和imu数据

一、rosbag相关的指令 1. rostopic list //列举出系统中正在发布的ros 话题 2. rosbag record -a //录制系统中所有正在发布的ros 话题 3. rosbag record topic1 topic2 .... -o bagname.bag 4. rosbag play bagname.bag //播放bag文件 5. rosbag info bagname.bag //查看…

PX4的workqueue

Workqueue相当于是中断子程序&#xff0c;然后在queue的cycle里面要注意&#xff0c;不能在cycle函数里面用printf打印&#xff0c;在cycle里面printf函数是打印不出来的。 也不能在cycle里面用while(1)&#xff0c;就是不能让程序一直在queue里面执行&#xff0c;要想让cycle执…

企业选择 多云管理平台 六大注意事项

企业选择 多云管理平台 六大注意事项 1、是否足够简单&#xff0c;学习曲线有多长 2、是否可实现自动化环境部署&#xff0c;日常运维作业等一系列操作&#xff1f; 3、是否可以管理全异构的云环境&#xff0c;支持主流公有云厂商的云资源&#xff1f; 4、是否能提供管理成本、…

面向接口编程

面向接口编程 一般在实现一个系统的时候,通常是将定义与实现合为一体,不加分离的&#xff0c;我认为最为理解的系统设计规范应该是所有的定义与实现分离&#xff0c;尽管这对于系统中某些复杂的情况有些繁烦。面向接口编程设计 使用面向接口编程思想将层与层之间通过接口依赖,下…

Java并发学习之一——线程的创建

与每个java语言中的元素一样&#xff0c;线程是对象。在Java中&#xff0c;我们有两种方式创建线程&#xff1a; 1、通过直接继承thread类&#xff0c;然后覆盖run方法。 2、构建一个实现Runnable接口的类&#xff0c;然后创建一个thread类对象并传递Runnable对象作为构造参数 …

day1||python

测试题&#xff1a; 0. Python 是什么类型的语言&#xff1f; Python是一种面向对象、解释型、动态类型计算机程序设计语言解释型&#xff1a;程序无需编译成二进制代码&#xff0c;而是在执行时对语句一条一条编译动态类型&#xff1a;在程序执行过程中&#xff0c;可以改变变…

2.7万字还原行业面貌,《2019 AI金融风控行业研究报告》正式上线!...

在金融科技领域&#xff0c;风险控制的重要性&#xff0c;从其关联的金融业务和结合的技术维度可见一斑&#xff1a;风控涉及信用借贷、保险、支付、供应链金融等场景&#xff0c;并运用了包括生物特征识别、机器学习、自然语言处理、大数据、云计算等多项技术。 区别于美国有…

【原创】QT简单计算器

代码 //main.cpp#include "calculator_111.h" #include <QtWidgets/QApplication>int main(int argc, char *argv[]) { QApplication a(argc, argv); Calculator_111 w; w.show(); return a.exec(); /* //QT creator Calculator_111 win; win.show(); return…