1、安装

 安装DjangoUeditor

  1)去GitHub上面下载djangoueditor源码包(https://github.com/twz915/DjangoUeditor3)

     然后进入源码的setup.py所在目录,执行pyton setup.py install安装。

  2)直接通过pip命令安装

    pip install DjangoUeditor

 然后将DjangoUeditor放到settings文件的INSTALLED_APPS中

2、配置url

  url(r"^ueditor/", include(DjangoUeditor.urls))

3、在model中使用

  from DjangoUeditor.models import UEditorField

  field = UEditorField(verbose_name = "", width=200, height=300, imagepath="", filepath="", default="", toolbar=[[]])

  常用参数说明:

    verbose_name:字段显示名

    width/height:富文本宽高

    imagepath/filepath:图片/文件存储相对路径(相对settings中配置的MEDIA_ROOT)

    toolbar:工具栏上的功能按钮,注意这里的toolbar是嵌套的列表

4、准备工作都做好了,接下来需要在xadmin中集成调用,集成方法:

  在xadmin--->plugin中新建ueditor.py(名字自定义),内容如下:

  

import xadmin
from xadmin.views import BaseAdminPlugin, CreateAdminView, UpdateAdminView
from DjangoUeditor.models import UEditorField
from DjangoUeditor.widgets import UEditorWidget
from django.conf import settings class XadminUEditorWidget(UEditorWidget):
def __init__(self, **kwargs):
self.ueditor_options = kwargs
self.Media.js = None
super(XadminUEditorWidget, self).__init__(kwargs) class UeditorPlugin(BaseAdminPlugin):
# 识别xadmin中的style_field
def get_field_style(self, attrs, db_field, style, **kwargs):
if style == "ueditor":
if isinstance(db_field, UEditorField):
widget = db_field.formfield().widget
param = {}
param.update(widget.ueditor_settings)
param.update(widget.attrs)
return {'widget' : XadminUEditorWidget(**param)}
return attrs # 在生成的页面中加入自己的js文件
def block_extrahead(self, context, nodes):
js = "<script type='text/javascript' src='%s'></script>"%(settings.STATIC_URL + "ueditor/ueditor.config.js")
js += "<script type='text/javascript' src='%s'></script>"%(settings.STATIC_URL+"ueditor/ueditor.all.min.js")
   nodes.append(js) xadmin.site.register_plugin(UeditorPlugin, UpdateAdminView)
xadmin.site.register_plugin(UeditorPlugin, CreateAdminView)

  然后在xadmin--->plugin--->__init__.py文件的PLUGINS中加入我们自定义的插件ueditor

    

  这样就完成了ueditor在xadmin中的集成

  最后,在注册modelXadmin的中,加入style_fields={"字段名":"ueditor"}

  

xadmin集成DjangoUeditor的更多相关文章

  1. django xadmin 集成DjangoUeditor富文本编辑器

    本文档记录自己的学习历程! 介绍 Ueditor HTML编辑器是百度开源的在线HTML编辑器,功能非常强大 额外功能 解决图片视频等无法上传显示问题 Ueditor下载地址 https://gith ...

  2. xadmin集成DjangoUeditor,以及编辑器的视频路径配置

    稍微讲一下DjangoUeditor的配置,因为之前去找配置的时候东拼西凑的,所以自己写一下自己一步步配置的过程.首先我是再github上去下载下来,因为是当作第三方插件集成到xadmin中,所以不用 ...

  3. 第三百九十五节,Django+Xadmin打造上线标准的在线教育平台—Xadmin集成富文本框

    第三百九十五节,Django+Xadmin打造上线标准的在线教育平台—Xadmin集成富文本框 首先安装DjangoUeditor3模块 Ueditor HTML编辑器是百度开源的HTML编辑器 下载 ...

  4. Django xadmin引入DjangoUeditor

    Django xadmin引入DjangoUeditor 版本:python3.6.1,Django1.11.1 DjangoUeditor下载地址:https://github.com/twz915 ...

  5. xadmin集成ueditor

    from DjangoUeditor.models import UEditorField content = UEditorField(u"内容", imagePath=&quo ...

  6. Xadmin集成富文本编辑器ueditor

    在xadmin中通过自定义插件,实现富文本编辑器,效果如下: 1.首先,pip安装ueditor的Django版本: pip install DjangoUeditor 2.之后需要添加到项目的set ...

  7. django2集成DjangoUeditor富文本编辑器

    富文本编辑器,在web开发中可以说是不可缺少的.django并没有自带富文本编辑器,因此我们需要自己集成,在这里推荐大家使用DjangoUeditor,因为DjangoUeditor封装了我们需要的一 ...

  8. Django使用xadmin集成富文本编辑器Ueditor(方法二)

    一.xadmin的安装与配置1.安装xadmin,其中第一种在python3中安装不成功,推荐第二种或者第三种 方式一:pip install xadmin 方式二:pip install git+g ...

  9. xadmin快速搭建后台管理系统

    一.xadmin的特点: 1.基于Bootstrap3:Xadmin使用Bootstrap3.0框架精心打造.基于Bootstrap3,Xadmin天生就支持在多种屏幕上无缝浏览,并完全支持Boots ...

随机推荐

  1. LeetCode题解之Keys and Rooms

    1.题目描述 2.问题分析 使用深度优先遍历 3.代码 bool canVisitAllRooms(vector<vector<int>>& rooms) { int ...

  2. Add correct host key in /root/.ssh/known_hosts to get rid of this message

    bug: Add correct host key in /root/.ssh/known_hosts to get rid of this message 解决办法: rm ~/.ssh/known ...

  3. Mysql的NULL和Empty String

    本文基于Mysql5.7版本的参考资料: https://dev.mysql.com/doc/refman/5.7/en/working-with-null.html https://dev.mysq ...

  4. 使用Java+MySQL+Apache开发后台项目(一)

    做前端开发的人越来越多,后端维护的人才越来越稀缺,这种趋势正在慢慢扩展.像我这种人总喜欢反其道而行之,做后端开发的人虽然减少了,但是工作量和工作资质都要求的更高了,随着人工智能的发展,需要后台处理的数 ...

  5. PCL学习笔记1

    先贴一段代码,从别处抄来的 #include <iostream> #include <pcl/io/pcd_io.h> #include <pcl/point_type ...

  6. Nginx location配置详解

    上一篇博客Nginx配置详解已经说过了nginx 的基本配置情况,今天来详细讲述一下nginx的location的配置原则, location是根据Uri来进行不同的定位,location可以把网站的 ...

  7. 转 CSS3+js实现多彩炫酷旋转圆环时钟效果

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  8. 【工具大道】UML的点点滴滴

    本文地址 点击关注微信公众号 wenyuqinghuai 分享提纲: 1. 概述 2. UML类图 3. UML时序图 4. 参考资料   1.概述   1.1)百度百科:           又称统 ...

  9. python 浅谈字典dict

    一.字典简介 字典(dict)是python中唯一的映射类型,他是以{ }括起来的键值对组成,在dict中的key是唯一的.在保存的时候,根据key来计算出一个内存地址.然后将key-value保存在 ...

  10. element ui Angular学习笔记(一)

    1.element ui安装 npm i --save element-angular 2.Angular-cli引入 引入后需要开启ElModule.forRoot(),也可以单独引入某个组件入El ...