zoukankan      html  css  js  c++  java
  • xadmin集成ueditor

    from DjangoUeditor.models import UEditorField

    content = UEditorField(u"内容", imagePath="uploadimg/",blank=True, null=True)

    在adminx.py里

    style_fields = {'content': 'ueditor'}

    在adminx里plugins里加入ueditor.py

    import xadmin
    from django.db.models import TextField
    from xadmin.views import BaseAdminPlugin, ModelFormAdminView, DetailAdminView
    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)}
                if isinstance(db_field, TextField):
                    return {'widget': XadminUEditorWidget}
            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, DetailAdminView)
    xadmin.site.register_plugin(UeditorPlugin, ModelFormAdminView)

    或者直接将目录放进项目

    再将ueditor.html放入templates中即可。

    在使用到的地方<p>{% autoescape off %}{{ information.content }}{% endautoescape %}</p>

  • 相关阅读:
    mysql BETWEEN操作符 语法
    mysql IN操作符 语法
    mysql LIKE通配符 语法
    mysql TOP语句 语法
    mysql DELETE语句 语法
    mysql Update语句 语法
    mysql INSERT语句 语法
    mysql ORDER BY语句 语法
    mysql OR运算符 语法
    mysql AND运算符 语法
  • 原文地址:https://www.cnblogs.com/tuifeideyouran/p/3935942.html
Copyright © 2011-2022 走看看