在python3裏面使用ueditor(基於adminx)

第一步,下載ueditor,在git上下載javascript

直接downloadhtml

https://github.com/twz915/DjangoUeditor3/ java

而後放到任何一個文件夾裏面node

配置setting and urlspython

INSTALLED_APPS = [
'DjangoUeditor',
]

#在工程裏面新建 media的文件上傳目錄
MEDIA_URL ='/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
#urls裏面配置
from extra_apps.DjangoUeditor import  urls as DjangoUeditor_urls

urlpatterns = [
    path('ueditor/', include(DjangoUeditor_urls)),
]

 

而後改app裏面的model,git

text = UEditorField(verbose_name='文本記錄',width=600, height=400,imagePath='user/ueditor/',filePath='user/ueditor/',default='')

 

而後在adminx.py裏面寫下調用類型github

style_fields = {'text':'ueditor'}

 

而後在adminx的plugin寫ueditor插件django

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)

 

在plugins裏面的_init_.py裏面配置好 ueditorapp

PLUGINS = (
'ueditor'
)

okurl

若是不出意外,應該已經生效了。能夠調用了

 

http://www.javashuo.com/article/p-pfetxorz-eq.html 

相關文章
相關標籤/搜索