当前位置: 首页 > news >正文

django-ckeditor配置html5video实现视频上传与播放

1. 手动下载插件

html5video的插件:https://github.com/bahriddin/ckeditor-html5-video
解压插件,将html5video放到ckeditor/ckeditor/plugins的目录里。

2. 修改ckeditor源码

1. 通过使用ckeditor->config.js->extraPlugins配置启用html5video插件

添加:

config.extraPlugins = 'html5video';

CKEDITOR.editorConfig = function( config ) {// Define changes to default configuration here. For example:// config.language = 'fr';// config.uiColor = '#AADC6E';config.allowedContent = true;config.extraPlugins = 'html5video';};

2. 将html5video加到CKEDITOR_CONFIGS里

CKEDITOR_CONFIGS = {'default': {'toolbar': 'Custom',  # 工具条功能'height': 600,  # 编辑器高度'width': 800,  # 编辑器宽'toolbar_Custom':[['Bold', 'Italic', 'Underline'],  # 粗体、斜体、下划线['Link', 'Unlink'],  # 链接、取消链接['NumberedList', 'BulletedList'],  # 有序、无序列表['Format'],  # 格式(如标题、段落)['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],  # 左对齐、居中、右对齐、两端对齐['Image', 'Html5video', 'Table', 'HorizontalRule'],  # 图片、表格、分割线['Undo', 'Redo'],  # 撤销、重做['Source'],  # 源代码模式],'stylesSet': [{'name': '1.5 倍行距', 'element': 'p', 'attributes': {'style': 'line-height: 1.5;'}}],'extraPlugins': ['html5video', 'widget', 'widgetselection', 'clipboard', 'lineutils'],},
}

 3. 前台渲染页面,video标签有播放控件

由于ckeditor渲染到页面上的代码是:

<div class="ckeditor-html5-video" style="text-align: center;">
       <video controlslist="nodownload" src="/media/upload/2025/07/08/ljzy_03.mp4">&nbsp;                 </video>
</div>

发现controlslist="nodownload"属性没有播放按钮,需要改成controls属性。

所以在渲染页面需要使用js进行修改:

<script>document.addEventListener('DOMContentLoaded', () => {const fixVideos = () => {try {const videos = document.querySelectorAll('.ckeditor-html5-video video');if (!videos.length) {console.warn('No videos found in .ckeditor-html5-video.');return;}videos.forEach((video, index) => {video.controls = true; // 添加 controlsvideo.removeAttribute('controlslist'); // 移除 controlslistconsole.log(`Fixed video ${index + 1}: Added controls, removed controlslist.`);});} catch (error) {console.error('Error fixing video controls:', error);}};// 初始修复fixVideos();// CKEditor 异步加载if (window.CKEDITOR) {CKEDITOR.on('instanceReady', fixVideos);CKEDITOR.on('change', () => setTimeout(fixVideos, 100));}// 动态内容监听const observer = new MutationObserver(fixVideos);observer.observe(document.body, { childList: true, subtree: true });});
</script>

参考文献:

django-ckeditor配置html5video上传视频 - SonnyZhang - 博客园

http://www.dtcms.com/a/269388.html

相关文章:

  • 基于Hadoop的用户购物行为可视化分析系统设计与实现
  • stm32 H7 ADC DMA采集
  • 240.搜索二维矩阵Ⅱ
  • c++-引用(包括完美转发,移动构造,万能引用)
  • 华为OD机试 2025B卷 - 数组组成的最小数字(C++PythonJAVAJSC语言)
  • 【Python进阶篇 面向对象程序设计(3) 继承】
  • 使用 GDB 调试 Redis 服务进程指南
  • pyhton基础【25】面向对象进阶六
  • 【ARM AMBA AXI 入门 21.1 -- AXI partial 访问和软件的按字节访问关系】
  • Transformer模型架构深度讲解
  • 医疗AI底层能力全链条工程方案:从技术突破到临床落地
  • L0:让大模型成为通用智能体的强化学习新范式
  • 针对Exhcnage Server的攻击防范措施
  • 机器人VLA模型(Vision-Language-Action)
  • 网络安全之XSS漏洞:原理、危害与防御实践
  • 基于mysql8.0.27部署1主2从的MHA集群
  • 从问题出发看Spring的对象创建与管理
  • JDBC 注册驱动的常用方法详解
  • 7.7晚自习作业
  • 两个法宝函数-dir()和help()
  • 网络基本知识和网络传输过程
  • 深度学习7(梯度下降算法改进1)
  • H3初识——入门介绍之serveStatic、cookie
  • AI + 数据治理的趋势:让治理更智能、更敏捷
  • linux操作系统---MySQL Galera Cluster部署
  • 开源 C# .net mvc 开发(八)IIS Express轻量化Web服务器的配置和使用
  • Vidwall: 支持将 4K 视频设置为动态桌面壁纸,兼容 MP4 和 MOV 格式
  • Python 的内置函数 setattr
  • 小架构step系列07:查找日志配置文件
  • Spring Boot登录认证实现学习心得:从皮肤信息系统项目中学到的经验