Django xadmin引入DjangoUeditor
生活随笔
收集整理的這篇文章主要介紹了
Django xadmin引入DjangoUeditor
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Django xadmin引入DjangoUeditor
版本:python3.6.1,Django1.11.1
DjangoUeditor下載地址:https://github.com/twz915/DjangoUeditor3
?
1、放入自定義第三方目錄,settings.py配置
import os import syssys.path.insert(0, os.path.join(BASE_DIR, 'extra_apps'))INSTALLED_APPS = ['django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','DjangoUeditor', ]2、urls.py配置
url(r'^ueditor/', include('DjangoUeditor.urls')),3、models.py配置
detail = UEditorField(verbose_name='詳情內容', width=1000, height=300,imagePath="uploads/images/",filePath="uploads/files/", default='', blank=True)?
xadmin插件引入
1、xadmin/plugin目錄下增加文件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 settingsclass XadminUEditorWidget(UEditorWidget):def __init__(self, **kwargs):self.ueditor_options = kwargsself.Media.js = Nonesuper(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().widgetparam = {}param.update(widget.ueditor_settings)param.update(widget.attrs)return {'widget': XadminUEditorWidget(**param)}return attrsdef 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)
2、xadmin/plugin目錄下__init__.py
PLUGINS = ('actions', 'filters', 'bookmark', 'export', 'layout', 'refresh','details','editable', 'relate', 'chart', 'ajax', 'relfield', 'inline', 'topnav', 'portal', 'quickform','wizard', 'images', 'auth', 'multiselect', 'themes', 'aggregation', 'mobile', 'passwords','sitemenu', 'language', 'quickfilter','sortablelist','execl','ueditor', )3、xadmin.py引入
style_fields = {'detail': 'ueditor'}4、上線后將ueditor靜態文件放入STATIC_ROOT
python manage.py collectstatic?
轉載于:https://www.cnblogs.com/shhnwangjian/p/7070790.html
總結
以上是生活随笔為你收集整理的Django xadmin引入DjangoUeditor的全部內容,希望文章能夠幫你解決所遇到的問題。