django 在admin中使用ueditor

在django xadmin中使用 Ueditor 在django的admin中使用Ueditor,只需要 pip install Django-Ueditor,然后按照说明文档安装即可。 但是如果后台使用了xadmin,Django-Ueditor就不起作用了,这里我就把在xadmin后台使用Ueditor的使用步骤展示出来分享给大家: 1. 基础环境 django-----》pip install djangodjango-u 阅读详情

代码部分参考了

http://www.yihaomen.com/article/python/238.htm

http://www.yihaomen.com/article/python/239.htm


大家也可以用DjangoUeditor


我的方法不需要安装,不过只是测试用,如果正式使用,最好还是要封装1个app


按照简单和复杂顺序写使用方法

1:下载ueditor到static目录下

2:urls.py添加

urlpatterns += patterns('',
    url(r'^js/(?P<path>.*)$', 'django.views.static.serve', {'document_root': 'static/js'}),
    url(r'^ueditor/(?P<path>.*)$', 'django.views.static.serve', {'document_root': 'static/ueditor'}),
    url(r'^ueditor_imgup$','zhenman.ueditor.views.ueditor_ImgUp'),
    url(r'^ueditor_fileup$','zhenman.ueditor.views.ueditor_FileUp'),
    url(r'^ueditor_getRemoteImage$','zhenman.ueditor.views.ueditor_getRemoteImage'),
    url(r'^ueditor_scrawlUp$','zhenman.ueditor.views.ueditor_ScrawUp'),
    url(r'^ueditor_getMovie$','zhenman.ueditor.views.ueditor_getMovie'),
    url(r'^ueditor_imageManager$','zhenman.ueditor.views.ueditor_imageManager'),

    url(r'^upload/(?P<path>.*)$', 'django.views.static.serve', {'document_root': 'media'}),
)


3:static/js目录下新建ueditorCustomConfig.js代码

(function($) {
    $(document).ready(function($) {
        var uedes=new UE.ui.Editor();
        uedes.render(id_description);//description为model中的字段名称
        var ueCon=new UE.ui.Editor();
        ueCon.render(id_content);//content为model中的字段名
    });
})(django.jQuery);


4:在admin.py文件中要注册的对象模型中添加:

class Media:
        # js = ('/js/tinymce/tinymce.min.js', '/js/textareas.js')
        js = ('/ueditor/ueditor.all.js', '/ueditor/ueditor.config.js' , '/js/ueditorCustomConfig.js')

5:在app中新建ueditor包,在ueditor包下新建views.py文件。代码如下

#coding: utf-8
__author__ = 'watsy'

from django.conf import settings
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
import Image
import os
import time
import urllib2
import uuid
import base64

def __myuploadfile(fileObj, source_pictitle, source_filename,fileorpic='pic'):
    """ 一个公用的上传文件的处理 """
    myresponse=""
    if fileObj:
        filename = fileObj.name.decode('utf-8', 'ignore')
        fileExt = filename.split('.')[1]
        file_name = str(uuid.uuid1())
        subfolder = time.strftime("%Y%m")
        MEDIA_ROOT = settings.MEDIA_ROOT[0] if isinstance(settings.MEDIA_ROOT , list) else settings.MEDIA_ROOT
        if not os.path.exists(MEDIA_ROOT + subfolder):
            os.makedirs(MEDIA_ROOT + subfolder)
        path = str(subfolder + '/' + file_name + '.' + fileExt)

        if fileExt.lower() in ('jpg', 'jpeg', 'bmp', 'gif', 'png',"rar" ,"doc" ,"docx","zip","pdf","txt","swf","wmv"):

            phisypath = MEDIA_ROOT + path
            destination = open(phisypath, 'wb+')
            for chunk in fileObj.chunks():
                destination.write(chunk)
            destination.close()

            if fileorpic=='pic':
                if fileExt.lower() in ('jpg', 'jpeg', 'bmp', 'gif', 'png'):
                    im = Image.open(phisypath)
                    im.thumbnail((720, 720))
                    im.save(phisypath)

            real_url = '/upload/' + subfolder + '/' + file_name + '.' + fileExt
            myresponse = "{'original':'%s','url':'%s','title':'%s','state':'%s'}" % (source_filename, real_url, source_pictitle, 'SUCCESS')
    return myresponse


@csrf_exempt
def ueditor_ImgUp(request):
    """ 上传图片 """
    fileObj = request.FILES.get('upfile', None)
    source_pictitle = request.POST.get('pictitle','')
    source_filename = request.POST.get('fileName','')
    response = HttpResponse()
    myresponse = __myuploadfile(fileObj, source_pictitle, source_filename,'pic')
    response.write(myresponse)
    return response


@csrf_exempt
def ueditor_FileUp(request):
    """ 上传文件 """
    fileObj = request.FILES.get('upfile', None)
    source_pictitle = request.POST.get('pictitle','')
    source_filename = request.POST.get('fileName','')
    response = HttpResponse()
    myresponse = __myuploadfile(fileObj, source_pictitle, source_filename,'file')
    response.write(myresponse)
    return response

@csrf_exempt
def ueditor_ScrawUp(request):
    """ 涂鸦文件,处理 """
    print request
    param = request.POST.get("action",'')
    fileType = [".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp"]

    if  param=='tmpImg':
        fileObj = request.FILES.get('upfile', None)
        source_pictitle = request.POST.get('pictitle','')
        source_filename = request.POST.get('fileName','')
        response = HttpResponse()
        myresponse = __myuploadfile(fileObj, source_pictitle, source_filename,'pic')
        myresponsedict=dict(myresponse)
        url=myresponsedict.get('url','')
        response.write("<script>parent.ue_callback('%s','%s')</script>" %(url,'SUCCESS'))
        return response
    else:
        #========================base64上传的文件=======================
        base64Data = request.POST.get('content','')
        subfolder = time.strftime("%Y%m")
        MEDIA_ROOT = settings.MEDIA_ROOT[0] if isinstance(settings.MEDIA_ROOT , list) else settings.MEDIA_ROOT
        if not os.path.exists(MEDIA_ROOT + subfolder):
            os.makedirs(MEDIA_ROOT + subfolder)
        file_name = str(uuid.uuid1())
        path = str(subfolder + '/' + file_name + '.' + 'png')
        phisypath = MEDIA_ROOT + path
        f=open(phisypath,'wb+')
        f.write(base64.decodestring(base64Data))
        f.close()
        response=HttpResponse()
        response.write("{'url':'%s',state:'%s'}" % ('/upload/' + subfolder + '/' + file_name + '.' + 'png','SUCCESS'))
        return response

def listdir(path,filelist):
    """ 递归 得到所有图片文件信息 """
    phisypath = settings.MEDIA_ROOT[0] if isinstance(settings.MEDIA_ROOT , list) else settings.MEDIA_ROOT
    if os.path.isfile(path):
        return '[]'
    allFiles=os.listdir(path)
    retlist=[]
    for cfile in allFiles:
        fileinfo={}
        filepath=(path+os.path.sep+cfile).replace("\\","/").replace('//','/')

        if os.path.isdir(filepath):
            listdir(filepath,filelist)
        else:
            if cfile.endswith('.gif') or cfile.endswith('.png') or cfile.endswith('.jpg') or cfile.endswith('.bmp'):
                filelist.append(filepath.replace(phisypath,'/upload/').replace("//","/"))


@csrf_exempt
def ueditor_imageManager(request):
    """ 图片在线管理  """
    filelist=[]
    phisypath = settings.MEDIA_ROOT[0] if isinstance(settings.MEDIA_ROOT , list) else settings.MEDIA_ROOT
    listdir(phisypath,filelist)
    imgStr="ue_separate_ue".join(filelist)
    response=HttpResponse()
    response.write(imgStr)
    return response


@csrf_exempt
def ueditor_getMovie(request):
    """ 获取视频数据的地址 """
    content =""
    searchkey = request.POST.get("searchKey")
    videotype = request.POST.get("videoType")
    try:
        url = "http://api.tudou.com/v3/gw?method=item.search&appKey=myKey&format=json&kw="+ searchkey+"&pageNo=1&pageSize=20&channelId="+videotype+"&inDays=7&media=v&sort=s"
        content=urllib2.urlopen(url).read()
    except Exception,e:
        pass
    response=HttpResponse()
    response.write(content)
    return response


@csrf_exempt
def ueditor_getRemoteImage(request):
    print request
    """ 把远程的图抓到本地,爬图 """
    file_name = str(uuid.uuid1())
    subfolder = time.strftime("%Y%m")
    MEDIA_ROOT = settings.MEDIA_ROOT[0] if isinstance(settings.MEDIA_ROOT , list) else settings.MEDIA_ROOT
    if not os.path.exists(MEDIA_ROOT + subfolder):
        os.makedirs(MEDIA_ROOT + subfolder)
    #====get request params=================================
    urls = str(request.POST.get("upfile"))
    urllist=urls.split("ue_separate_ue")
    outlist=[]
    #====request params end=================================
    fileType = [".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp"]
    for url in urllist:
        fileExt=""
        for suffix in fileType:
            if url.endswith(suffix):
                fileExt=suffix
                break
        if fileExt=='':
            continue
        else:
            path = str(subfolder + '/' + file_name + '.' + fileExt)
            phisypath = MEDIA_ROOT + path
            piccontent= urllib2.urlopen(url).read()
            picfile=open(phisypath,'wb')
            picfile.write(piccontent)
            picfile.close()
            outlist.append('/upload/' + subfolder + '/' + file_name + '.' + fileExt)
    outlist="ue_separate_ue".join(outlist)

    response=HttpResponse()
    myresponse="{'url':'%s','tip':'%s','srcUrl':'%s'}" % (outlist,'成功',urls)
    response.write(myresponse)
    return response


DjangoUeditor3-2.0二次开发完美版,支持python3和django2.0以上。 DjangoUeditor3-2.0二次开发完美版,支持python3和django2.0以上。 经过不懈的努力,在官网停止开发的基础上,修改开发成支持python3和django2.0以上的环境。 经过不懈的努力,在官网停止开发的基础上,修改开发成支持python3和django2.0以上的环境。 经过不懈的努力,在官网停止开发的基础上,修改开发成支持python3和django2.0以上的环境。 经过不懈的努力,在官网停止开发的基础上,修改开发成支持python3和django2.0以上的环境。 经过不懈的努力,在官网停止开发的基础上,修改开发成支持python3和django2.0以上的环境。 经过不懈的努力,在官网停止开发的基础上,修改开发成支持python3和django2.0以上的环境。 经过不懈的努力,在官网停止开发的基础上,修改开发成支持python3和django2.0以上的环境。 经过不懈的努力,在官网停止开发的基础上,修改开发成支持python3和django2.0以上的环境。 立即下载

相关推荐

Arch Linux双系统安装避坑指南:从Windows分区到桌面环境全流程

本文提供了一份详尽的Arch Linux与Windows双系统安装避坑指南。内容涵盖从安装前的UEFI环境确认、BitLocker处理、分区规划,到Live环境进入、基础系统安装、GRUB引导配置,再到显卡驱动安装、KDE/GNOME桌面环境部署及中文化设置的全流程。重点解决了双系统安装中的核心痛点,帮助用户在不破坏现有Windows系统的前提下,顺利完成Arch Linux的安装。

nice1的博客 535

Django使用xadmin集成富文本编辑器Ueditor(方法二)

一、xadmin的安装与配置1、安装xadmin,其中第一种在python3中安装不成功,推荐第二种或者第三种 1 方式一:pip install xadmin 2 方式二:pip install git+git://github.com/sshwsfc/xadmin.git 3 方式三:下载https://codeload.github.com/sshwsfc/xadmin/...

子钦加油的博客 215

【电路设计实战】BUCK降压电路:从原理到PCB布局的降噪与效率优化

本文深入剖析了BUCK降压电路的工作原理,并针对其固有的开关噪声问题,提供了从核心元件选型到PCB布局的全面优化方案。文章重点探讨了电感、电容等关键元件的选型要点,强调了低ESR电容和肖特基二极管的重要性,并详细阐述了如何通过最小化功率回路、保护敏感信号线等PCB布局实战技巧,有效抑制噪声、提升效率与稳定性。

weixin_29304021的博客 219

Django-xadmin富文本ueditor编辑配置,并解决图片不显示的问题

首先下载 DjangoUeditor :https://github.com/twz915/DjangoUeditor3 安装DjangoUeditor 这是去官网下载并进行安装,但是不兼容python3 pip install DjangoUeditor 这里选择下载源码安装,考虑兼容性问题,进入压缩目录,执行以下安装语句 python setup.py DjangoUeditor ...

geek_xiong的博客 2878

别再怕非观测区了!手把手教你用移相法搞定PMSM单电阻FOC的电流重构难题

本文详细解析了永磁同步电机(PMSM)单电阻FOC系统中非观测区的电流重构难题,重点介绍了移相法的工程实践。通过STM32平台的具体实现和调试指南,帮助工程师有效解决相电流检测中的采样窗口不足问题,提升系统稳定性和性能。

weixin_27252001的博客 433

期末求生指南:手把手教你用浏览器开发者工具绕过百一测评切屏检测

本文详细介绍了如何利用浏览器开发者工具绕过百一测评的切屏检测功能。通过分析JavaScript事件监听机制,定位关键检测代码,并提供实时调试和本地覆盖两种修改方法,帮助学生在遵守规则的前提下更灵活地应对在线考试。文章还包含风险控制和替代方案等实用建议。

weixin_28698059的博客 547

Django使用DjangoUeditor教程

文章目录1、将下在DjangoUeditor解压2、将解压的文件夹复制到项目的根目录中,这里使用的是虚拟环境3、进入到DjangoUedior3-master文件下,执行离线安装命令 python setup.py install4、然后将DjangoUeditor3-master文件夹删除,避免影响项目结构5、执行pip list 查看是否安装成功,如果目录下有DjangoUeditor代表安装...

折戟沉沙 8190

数学建模国赛C题实战:从数据预处理到模型优化的完整流程(附Python代码)

本文系统讲解了数学建模国赛C题的完整实战流程,涵盖从数据预处理、模型选择与构建到优化与结果可视化的关键步骤。文章重点分享了如何利用Python进行高效的数据清洗、特征工程,并提供了多种机器学习模型的实现代码与对比验证方法,旨在帮助参赛者构建逻辑清晰、结果可靠的解决方案。

weixin_29079643的博客 293

【亲测免费】 推荐项目:DjangoUeditor3 - 强大的 Django 富文本编辑器

推荐项目:DjangoUeditor3 - 强大的 Django 富文本编辑器 项目简介 是一个基于 Django 框架的富文本编辑器组件,它将流行的 UEditor 集成到 Django 应用中,为开发者提供了便捷的文本编辑和管理工具。该项目由 twz915 开发并维护,旨在提升 Web 应用的内容创作体验。 技术分析 Django集成:DjangoUeditor3 紧密地与 Django ...

gitblog_00059的博客 1012

新年美食鉴赏——基于注意力机制CBAM的美食101分类

新年美食鉴赏——基于注意力机制CBAM的美食101分类一、数据预处理1.数据集介绍2.读取标签3.统一命名4.整理图片路径5.划分训练集与验证集6.定义美食数据集二、注意力机制1.简介2.卷积块注意力网络——CBAM通道注意力模块CAM空间注意力模块SAM3.将通道、空间注意力模块合并三、基于卷积块注意力模块的ResNet-CBAM1.代码实现2.模型测试3.查看网络结构4.模型训练5.模型预测四、总结与升华个人简介 春节是一年当中最隆重、最盛大的节日,吃得最好的一餐可能就是年夜饭了,想想就很激动呢!随着新

zbp_12138的博客 1万+

Python爬虫实战:全面解析裁判文书网法律文书抓取与分析

本文详细介绍了如何使用Python爬虫技术,分别通过Requests+BeautifulSoup、Selenium和Scrapy等方式,爬取裁判文书网的法律文书信息,并进行了验证码处理、数据存储和可视化分析。网页结构分析与数据提取;爬虫框架的使用;验证码处理策略;数据分析与可视化。爬取更多法律文书网站的数据;爬取文书的全文内容;构建法律文书搜索引擎;使用自然语言处理技术对法律文书进行深入分析。

2201_76125261的博客 1330

在非admin页面使用 Django Ueditor

Django Ueditor的安装和在admin页面的使用请看,接下来的内容是基于这篇文章的环境进行的:如何使用 Django Ueditor,如果你按照下面的流程来做还有关于Ueditor的报错,很有可能是没有装好环境。。 总体流程 以文章模型为例 1、创建文章模型 2、创建该文章模型的Form 3、写个html界面 4、写个视图函数article(),并提供这个Form给前端渲染 5、...

haifeng10001的博客 528

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

ueditor版本python3_【DjangoUeditor】Django百度富文本编辑器的加载使用(本章admin后台使用) python3...

1:下载编辑器适配版本: python32:建立文件夹放入包建立包extra_apps,将包放入文件夹里,右键点击extra_apps选中菜单mark directory as 选择 sources root 就可以编程蓝色文件夹目录,如图所示,1:路由设置:打开ulrs.py, 添加路由:url(r’^ueditor/’,include(‘DjangoUeditor.DjangoUeditor...

weixin_39963440的博客 136

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

ueditor编辑框在django项目的admin页面不显示,完美解决

原因:服务器无法获取到DjangoUeditor的静态文件 解决: 1、找到静态文件 2、粘贴到项目的static目录 3、重启服务器,OK

qq_34045989的博客 611

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

django2.1.2使用xadmin和UEditor美化admin后台+minicms的小坑

django2.1.2的后台实在不够美观。采用xadmin美化后台。 下载xadmin的zip,解压后把xadmin文件夹放入项目extra_pps文件夹内。同时将extra_apps设置为resourse root 之后的配置参照博客: https://blog.youkuaiyun.com/bysjlwdx/article/details/80853655 运行后会报错: render() ...

qq_35733521的博客 1888

django后台模板admin在使用百度富文本编辑ueditor的bug解决

记录一下,花了点时间想明白这个问题。 首先我要做的是:兼职的项目,django的后台(admin那个)有一个表是新闻,为了项目的运营人员的好操作,我要把这个模块改成富文本编辑。 然后为了改的最少,我的偷懒方法是:后台模板自动输出的新闻内容有一个div,我们叫做div1好了,然后富文本编辑有一个编辑框,我们叫做div2好了。 然后就是div1里面的内容先读进变量temp,把temp...

weixin_30408165的博客 148

django 三天写个人博客

主要主题         1    模板使用  前端技术不好 使用模板 节约不少时间  本来也没有能力做这样的前端模板。yangqq.com 的模板。 2   admin 使用   注册Admin    后台基本不要写了    节约大量时间  管理     类别  博文 评论   相册 链接  心情  可以增删查改         3     model  关于多对一的查找   ca

xyjikl 1193

ueditor版本python3_【Django组件】DjangoUeditor百度富文本编辑器的加载使用(本章admin后台使用) python3...

1:下载编辑器适配版本: python32:创建文件夹放入包创建包extra_apps,将包放入文件夹里,右键点击extra_apps选中菜单mark directory as 选择 sources root 就可以编程蓝色文件夹目录,如图所示,1:路由配置:打开ulrs.py, 添加路由:url(r'^ueditor/',include('DjangoUeditor.DjangoUeditor...

weixin_39901412的博客 159

Django + xadmin +Ueditor

一,下载ueditorde js文件,放到static文件下,    二,配置setting, INSTALLED_APPS = [  'DjangoUeditor',   'crispy_forms', ] STATIC_URL = '/static/'MEDIA_ROOT = BASE_DIR + '/static/upload/upimg/'MEDIA_URL = '...

banyoming7502的博客 133

html 实现富文本编辑器实例,django富文本编辑器的实现示例

如何在Django项目中使用UEditor(百度的富文本编辑直接扔到模版里就能用了呗。请问django如何接入tinymce富文本编辑器?django富文本编辑器截取前多少文本其实从html富文本中提取纯文本很简单,富文本基本上是使用html标签给文本加上丰富多彩的样式。 所以只需要将富文本字符串中的“”标签剔除,即可得到纯文本。如何在 Django 后台 admin 中集成一个富文本编辑器一、下...

weixin_42510453的博客 359

百度html在线编辑器插件,百度编辑器UEditor插件DjangoUeditor v1.8.143

DjangoUeditor将Ueditor封装为一个Django app,提供文件/图片等上传功能,提供UEditorField、UEditorWidget等封装类,简化Ueditor在Django中的应用。注:Django是Python世界影响最大的Web框架。本模块帮助在Django应用中集成百度Ueditor HTML编辑器,Django是Python世界最有影响力的web框架。 Uedit...

weixin_39747807的博客 443

Django Ueditor之原样展示已有的富文本内容到富文本编辑器

在上一篇文章(在非admin页面使用 Django Ueditor)中我们使用form向前端模板渲染了Ueditor富文本编辑器界面,但当时只讲到了创建一个新文本内容的界面的做法,对于该文本内容的二次展示和修改并未作进一步解释。 注意:下面教程内容基于上一篇文章的环境,如对下文的表述不理解,建议先翻看上一篇文章,下文仍是以文章模型为例。 三步走 1、写一个url 首先,请求时是要带上能识别...

haifeng10001的博客 937

富文本框编辑器

第一种方法 第一步,安装django-tinymce 第二步,在setting文件中配置 INSTALLED_APPS={ #添加富文本框编辑器这个模块 'tinymce', } #在setting配置中配置tinymce的配置项参数 # tinymce 的配置项 TINYMCE_JS_URL = "/static/tiny_mce/tiny_mce.js" T...

weixin_44455142的博客 410

在python3里面使用ueditor(基于adminx)

第一步,下载ueditor,在git上下载 直接download :https://github.com/twz915/DjangoUeditor3/ 然后放到任何一个文件夹里面 配置setting and urls INSTALLED_APPS=['DjangoUeditor',]#在工程里面新建media的文件上传目录MEDIA_URL='/media/'MED...

weixin_30244889的博客 232

Django Server Error (500) 一种解决方式

在上线调试Django 项目的时候,发现通过admin向某个数据库中表添加数据的时候,显示ServerError(500)。。。但是向其他表添加数据时一切正常。 用到Ueditor,有时会遇到这个问题。 解决步骤: 1. 将部署到阿里云上的项目Debug 改成True 2. 重启该项目,继续向该表中插入数据,查看报错: render()gotanunexpectedkeywordargument'renderer' 3. 这种错误是由于使用了Ueditor导致的, 4. 把/us...

佳梦作快马 诗酒趁年华 1万+
上一篇: django支持动态百度sitemap
下一篇: 数据标准化基础及说明
watsy
博客等级 码龄19年 133粉丝 104原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值