https://github.com/twz915/DjangoUeditor3 下載地址
1. 把DjangoUeditor 文件 復(fù)制到 extra_app 目錄下
2. 在settings 中 配置INSTALLED_APPS 加入'DjangoUeditor'
3. 在urls 中 配置 path(r'ueditor/', include('DjangoUeditor.urls')),
4. 在models 中導(dǎo)入 from DjangoUeditor.models import UEditorField
? ? detail = UEditorField(verbose_name='機構(gòu)詳情',
? ? ? ? ? ? ? ? ? ? ? ? ? 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 = '<script type="text/javascript" src="%s"></script>' % (
? ? ? ? ? ? settings.STATIC_URL + "ueditor/ueditor.config.js")? # 自己的靜態(tài)目錄
? ? ? ? js += '<script type="text/javascript" src="%s"></script>' % (
? ? ? ? ? ? settings.STATIC_URL + "ueditor/ueditor.all.js")? # 自己的靜態(tài)目錄
? ? ? ? nodes.append(js)
xadmin.site.register_plugin(UeditorPlugin, UpdateAdminView)
xadmin.site.register_plugin(UeditorPlugin, CreateAdminView)
在 __init__文件中 注冊此文件 PLUGINS 中添加 ueditor,
6.在相應(yīng)adminx 中添加
style_fields = {'detail':'ueditor'}
7.然后遷移數(shù)據(jù)庫
如果遇到 TypeError: render() got an unexpected keyword argument 'renderer' 問題?
直接 注釋掉? ? ? ? ? ? # renderer=self.form.renderer, 此部分代碼