稍微講一下DjangoUeditor的配置,由於以前去找配置的時候東拼西湊的,因此本身寫一下本身一步步配置的過程。首先我是再github上去下載下來,由於是看成第三方插件集成到xadmin中,因此不用pip安裝,直接和xadmin放一個目錄就ok了。javascript
#!/usr/bin/env python # -*- 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.min.js") #本身的靜態目錄 nodes.append(js) xadmin.site.register_plugin(UeditorPlugin, UpdateAdminView) xadmin.site.register_plugin(UeditorPlugin, CreateAdminView)
content = UEditorField(verbose_name='內容', width=600, height=300, toolbars='full', imagePath='guide/images/', filePath='', upload_settings={'imageMaxSize': 1204000, 'videoPathFormat': "guide/videos/%(basename)s_%(datetime)s.%(extname)s"}, default='')
class GuideWordAdmin(object): style_fields = {'content': 'ueditor'} xadmin.site.register(GuideWord, GuideWordAdmin)
UEDITOR_SETTINGS = { 'config': { }, 'upload': { "imageUrlPrefix": "http://127.0.0.1:8000", "videoUrlPrefix": "http://127.0.0.1:8000", "fileUrlPrefix": "http://127.0.0.1:8000", } }