Django + xaadmin +Ueditor
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django + xaadmin +Ueditor相关的知识,希望对你有一定的参考价值。
一,下载ueditorde js文件,放到static文件下,
二,配置setting,
INSTALLED_APPS = [
‘DjangoUeditor‘
]
STATIC_URL = ‘/static/‘
MEDIA_ROOT = BASE_DIR + ‘/static/upload/upimg/‘
MEDIA_URL = ‘/static/upload/upimg/‘
STATICFILES_DIRS = [
‘static‘,
BASE_DIR + ‘/static/‘
]
三,配置url
from django.conf.urls import url,include
url(r‘^ueditor/‘, include(‘DjangoUeditor.urls‘)),
四,在adminx.py里配置
class ModuleInterDisplay(object):
style_fields = {"content": ‘ueditor‘}
def get_field_style(self, db_field, style, **kwargs):
if style in (‘ueditor‘,):
attrs = {‘widget‘: Ueditor} # 此处是顶部的widget引用
return attrs
五,建一个rte文件夹:里面包含__init__.py 和widgets.py,在widgets.py里放:
__author__=‘Administrator‘
#coding=utf-8
from django import forms
from django.conf import settings
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
class Ueditor(forms.Textarea):
def __init__(self, attrs={}):
super(Ueditor, self).__init__(attrs)
def render(self, name, value, attrs=None):
# rendered = super(Ueditor,self).render(name,value,attrs)
context = {
‘name‘: name,
‘STATIC_URL‘: settings.STATIC_URL,
‘value‘: value,
}
return mark_safe(render_to_string(‘widgets/ueditor.html‘, context))
以上是关于Django + xaadmin +Ueditor的主要内容,如果未能解决你的问题,请参考以下文章
django——xadmin中集成富文本编辑器ueditor