效果图:

步骤:

1.利用命令:pip install DjangoUeditor,安装DjangoUeditor,但由于DjangoUeditor没有python3版本的,从的Github上把修改好的UEditor Down下来,然后放在自己的extra_apps文件夹中

并在setting.py文件中去添加路径配置

import os
import sys
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
# 设置 extra_apps 目录
# 项目文件夹下的setting文件 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(BASE_DIR, 'extra_apps'))

2.将DjangoUeditor 添加到settings.py文件的APP 里边

INSTALLED_APPS = [
....
# 配置富文本编辑器
'DjangoUeditor',
]

3.在urls.py文件中配置路由信息

#添加富文本路径信息
url(r'^ueditor/', include('DjangoUeditor.urls')),

4.修改models对应的字段


from DjangoUeditor.models import UEditorField
class Article(models.Model):
....
content = UEditorField(verbose_name='内容', height=400, width=800,
default=u'', imagePath="Article_img/%%Y/%%m/",
toolbars='full', filePath='Article_file/%%Y/%%m/',
upload_settings={"imageMaxSize": 1204000},
settings={}, command=None, )

5.在settings.py 设置 static 和 media

# 公共的 static 文件,比如 jquery.js 可以放这里,这里面的文件夹不能包含 STATIC_ROOT
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "common_static"),
) # upload folder
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

6.在urls.py 文件添加:

from django.conf import settings
...
if settings.DEBUG:
from django.conf.urls.static import static
urlpatterns += static(
settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

6.在xadmin中添加Ueditor文件

在xadmin下的plugin中新建ueditor.py文件(我的是在extra_apps/xadmin,也可以在site_packages中找到对应的文件夹)添加如下代码:

#!/usr/bin/python3
# -*-coding:utf-8-*- import xadmin
from xadmin.views import BaseAdminPlugin, CreateAdminView, ModelFormAdminView, 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):
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 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.js") # 自己的静态目录
nodes.append(js) xadmin.site.register_plugin(UeditorPlugin, UpdateAdminView)
xadmin.site.register_plugin(UeditorPlugin, CreateAdminView)
7.将ueditor添加到plugin下的init中
PLUGINS = (
.....
'ueditor',
)

8.将ueditor添加到项目app里面的adminx.py中(!!!之前由于没有添加一直无法显示)

class ArticleAdmin(object):
style_fields = {'content': 'ueditor'}
......

7.在前端显示的话,需要对html页面修改如下

{% autoescape off %}
{{ course.detail }}
{% endautoescape %}

本博客参考:https://blog.csdn.net/wgpython/article/details/79585205

Django xadmin后台添加富文本编辑器UEditor的用法的更多相关文章

  1. django—xadmin中集成富文本编辑器ueditor

    一.安装 pip命令安装,由于ueditor为百度开发的一款富文本编辑框,现已停止维护,如果解释器为python2,则直接pip install djangoueditor 解压包安装,python3 ...

  2. Django项目中添加富文本编辑器django-ckeditor

    django-ckeditor库的使用步骤: 1.在命令行下安装django-ckeditor这个库: 命令:pip install django-ckeditor 2.安装成功后,配置Django项 ...

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

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

  4. 百度富文本编辑器UEditor安装配置全过程

    网站开发时富文本编辑器是必不可少的,他可以让用户自行编辑内容的样式然后上传到后台!下面我们来介绍如何安装使用百度富文本编辑器 一.下载并且设置百度富文本编辑器的样式     你可以去百度UEditor ...

  5. 富文本编辑器UEditor自定义工具栏(二、插入图片、音频、视频个性化功能按钮和弹层及自定义分页符)

    导读:本篇将简单探讨插入图片.音频.视频的功能按钮实现方式 传送门:富文本编辑器UEditor自定义工具栏(一.基础配置与字体.背景色.行间距.超链接实现) 一.效果图 1.UEditor自定义工具栏 ...

  6. springboot+layui 整合百度富文本编辑器ueditor入门使用教程(踩过的坑)

    springboot+layui 整合百度富文本编辑器ueditor入门使用教程(踩过的坑) 写在前面: ​ 富文本编辑器,Multi-function Text Editor, 简称 MTE, 是一 ...

  7. 百度Web富文本编辑器ueditor在ASP.NET MVC3项目中的使用说明

    ====================================================================== [百度Web富文本编辑器ueditor在ASP.NET M ...

  8. 百度富文本编辑器ueditor使用总结

    最近做的项目用到了ueditor这个东东,但是他的一些配置文档对初次使用者来说很难以理解,故作此总结 相关详细操作链接地址: http://blog.csdn.net/wusuopubupt/arti ...

  9. 富文本编辑器UEditor自定义工具栏(三、自定义工具栏功能按钮图标及工具栏样式简单修改)

    导读 富文本编辑器UEditor提供丰富了定制配置项,如果想设置个性化的工具栏按钮图标有无办法呢?答案是肯定的!前两篇博文简要介绍了通过将原工具栏隐藏,在自定义的外部按钮上,调用UEditor各命令实 ...

随机推荐

  1. pod install vs pod update

    Podfile文件,Podfile.lock文件 Podfile文件:指定依赖库的版本规则 Podfile.lock文件:记录当前工程中使用的依赖库的版本号 pod install会去安装podfil ...

  2. ReactiveX 学习笔记(16)RxPY

    RxPY RxPY 是 ReactiveX 的 Python语言实现. # 安装 RxPY $ pip3 install rx Successfully installed rx-1.6.1 Basi ...

  3. android填满手机内存的方法

    1. 进行临界测试,手机盘空间存满的条件下应用会有何表现:通常手动添加大文件但是还是不够,通过如下 2. 使用adb命令完成:通过如下 adb 命令在 /mnt/sdcard/ 目录下产生一个名为 b ...

  4. 面图层拓扑检查和错误自动修改—ArcGIS案例学习笔记

    面图层拓扑检查和错误自动修改-ArcGIS案例学习笔记 联系方式:谢老师,135_4855_4328,xiexiaokui#139.com 数据源: gis_ex10\ex01\parcel.shp, ...

  5. pandas数据操作

    pandas数据操作 字符串方法 Series对象在其str属性中配备了一组字符串处理方法,可以很容易的应用到数组中的每个元素 t = pd.Series(['a_b_c_d','c_d_e',np. ...

  6. /src/log4j.xml

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration S ...

  7. react ES5 与ES6的写法

    ES5var React = require('react'); var ReactDOM = require('react-dom'); // 定义组件 var HelloMessage = Rea ...

  8. 八、AbstractFactory 抽象工厂模式

    设计原理: 代码清单: 抽象 Factory : public abstract class Factory { public static Factory getFactory(String cla ...

  9. django创建一个简单的web站点

    一.新建project 使用Pycharm,File->New Project…,选择Django,给project命名 (project不能用test命名)   新建的project目录如下: ...

  10. ASP.NET 登录验证 ihttpmoudle

    问题: 1.iis版本不同(IIS7.0,应用程序池采用的是集成模式,换成经典模式才起作用.) 在 IIS 7 以下的版本中,应用以下配置: <system.web> <httpMo ...