DjangoUeditor添加与配置
作者:互联网
一、xadmin添加富文本插件
1. xadmin/plugins文件夹下新建文件ueditor.py
# xadmin/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") 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. 把插件添加到__init__.py里面
# xadmin/plugins/__init__.py PLUGINS = ( 'ueditor', )
二、url配置
配置xadmin和ueditor的路由
# MxShop/urls.py import xadmin from django.urls import path,include urlpatterns = [ path('xadmin/', xadmin.site.urls), path('ueditor/', include('DjangoUeditor.urls')), ]
三、注册app到xadmin后台
users/adminx.py
# users/adminx.py __author__ = 'derek' import xadmin from xadmin import views from .models import VerifyCode class BaseSetting(object): #添加主题功能 enable_themes = True use_bootswatch = True class GlobalSettings(object): #全局配置,后台管理标题和页脚 site_title = "仙剑奇侠传" site_footer = "http://www.cnblogs.com/derek1184405959/" #菜单收缩 menu_style = "accordion" class VerifyCodeAdmin(object): list_display = ['code', 'mobile', "add_time"] xadmin.site.register(VerifyCode, VerifyCodeAdmin) xadmin.site.register(views.BaseAdminView, BaseSetting) xadmin.site.register(views.CommAdminView, GlobalSettings)
修改app名字为中文
# users/apps.py from django.apps import AppConfig class UsersConfig(AppConfig): name = 'users' #app名字后台显示中文 verbose_name = "用户管理"
还需要__init__.py中修改默认配置才生效
# users/__init__.py default_app_config = 'users.apps.UsersConfig'
标签:__,ueditor,xadmin,DjangoUeditor,配置,site,添加,import,py 来源: https://www.cnblogs.com/mxsf/p/10661681.html