http://xadmin.readthedocs.io/en/docs-chinese/make_plugin.html#id1
djangoueditor是把UEditor集成到了django中,是一个属于django的app
大家可以在github.com上搜索 djangoueditor
https://github.com/search?q=djangoueditor
第一个就是DjangoUeditor的源码
如果大家不能访问github.com
进入百度,搜索pypi
点击进入,并搜索djangoueditor
下载开发包
点击 链接 进入 https://github.com/zhangfisher/DjangoUeditor
安装:
安装好之后
detail = models.Content=UEditorField(verbose_name=u"课程详情", width=600, height=300, imagePath="courses/ueditor/", filePath="courses/ueditor/", default="")
在 目录 C:\Users\hlg\PycharmProjects\MxOnline\extra_apps\xadmin\plugins 新建一个py文件
然后把一下内容拷贝进来
# -*- 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 = '' % (settings.STATIC_URL + "ueditor/ueditor.config.js") #自己的静态目录
js += '' % (settings.STATIC_URL + "ueditor/ueditor.all.min.js") #自己的静态目录
nodes.append(js)
xadmin.site.register_plugin(UeditorPlugin, UpdateAdminView)
xadmin.site.register_plugin(UeditorPlugin, CreateAdminView)
富文本已经生效
前端页面里,
是因为django默认开启转义
关闭转义
{% autoescape off %}
{{ course.detail }}
{% endautoescape %}