1.https://github.com/twz915/DjangoUeditor3下载包,进入包文件夹,找到DjangoUeditor包拷贝到项目下,和xadmin同级目录

2.找到项目的settings文件,注册app

3.找到项目urls文件,配置DjangoUeditor路由

4.找到app下的models,在需要使用富文本框的字段使用UEditorField,相关参数含义可参考文档:https://github.com/zhangfisher/DjangoUeditor
- fromimport
- content=UEditorField(verbose_name='博客内容'
- 700
- 400
- 'full'
- 'ueditor/images/'
- 'ueditor/files/'
- 'imageMaxSizing':1024000
- ''
5.xadmin中添加插件ueditor
由于已经将xadmin源文件拷贝到了项目下,为extra_apps/xadmin,在xadmin下的plugin中新建一个ueditor.py文件,添加以下代码:
- import
- fromimport
- fromimport
- fromimport
- fromimport
- class
- defself
- self
- selfNone
- self
- class
- defself
- if'ueditor'
- if
- return'widget'
- return
- defself
- "ueditor/ueditor.config.js"#自己的静态目录
- "ueditor/ueditor.all.min.js"#自己的静态目录
6.将ueditor插件添加到plugins中的__init__.py的PLUGINS中

7.找到app下的adminx.py文件,配置插件

8.配置上传文件的加载路径
1.在settings里面配置
- MEDIA_URL='/media/'
- MEDIA_ROOT=os.path.join(BASE_DIR,'media'
- fromimport
- url(r'^media/(?P<path>.*)$',serve,{"document_root":settings.MEDIA_ROOT},name='media'
文章来源: 富文本编辑器