https://github.com/twz915/DjangoUeditor3 下载地址
1. 把DjangoUeditor 文件 复制到 extra_app 目录下
2. 在settings 中 配置INSTALLED_APPS 加入'DjangoUeditor'
3. 在urls 中 配置 path(r'ueditor/', include('DjangoUeditor.urls')),
4. 在models 中导入 from DjangoUeditor.models import UEditorField
detail = UEditorField(verbose_name='机构详情',
width=700,
height=600,
toolbars='full',
imagePath='ueditor/image/',
filePath='ueditor/files/',
upload_settings={'imageMaxSizing':102400},
default=''
)
5. 在xadmin中添加 ueditor
在plugins 中添加 ueditor.py 文件 加入以下代码
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 = '' % (
settings.STATIC_URL + "ueditor/ueditor.config.js") # 自己的静态目录
js += '' % (
settings.STATIC_URL + "ueditor/ueditor.all.js") # 自己的静态目录
nodes.append(js)
xadmin.site.register_plugin(UeditorPlugin, UpdateAdminView)
xadmin.site.register_plugin(UeditorPlugin, CreateAdminView)
在 __init__文件中 注册此文件 PLUGINS 中添加 ueditor,
6.在相应adminx 中添加
style_fields = {'detail':'ueditor'}
7.然后迁移数据库
如果遇到 TypeError: render() got an unexpected keyword argument 'renderer' 问题
直接 注释掉 # renderer=self.form.renderer, 此部分代码