xadmin 集成ueditor
GitHub搜索 djangoueditor 查看使用教程
下载djangoueditor或者 直接使用源码包
配置ueditor url:
url('^ueditor/', include('DjangoUeditor.urls')),
写xadmin插件:
xadmin/plugins 目录下添加 一个文件(ueditor.py)
文件内容如下:
-- coding: utf-8 --
author = 'bobby'
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.min.js") #自己的静态目录
nodes.append(js)
xadmin.site.register_plugin(UeditorPlugin, UpdateAdminView)
xadmin.site.register_plugin(UeditorPlugin, CreateAdminView)
xadmin/plugins 下面的 init.py 注册刚刚写好的插件
修改需要使用Ueditor 的adminx文件中的相应类:
添加style_fields= { }
class GoodsAdmin(object):
style_fields = {"goods_desc":"ueditor"}
前端不能正常显示是因为django开启的 自动转义(类似