django 与 百度 ueditor 富文本编辑器集成
生活随笔
收集整理的這篇文章主要介紹了
django 与 百度 ueditor 富文本编辑器集成
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
django 是基于 python 的一個很好的web開發框架。ueditor 是百度開源的一個富文本編輯器。有很好的用戶體驗,很適合中國人使用的一個編輯器。
在使用ueditor 之前,我集成過 fckeditor , ckeditor 。基本沒什么難度。但功能沒有ueditor 強大。因此產生了用django 集成 ueditor 的想法。
查看了百度官方的文檔以及例子,發現只有 java,php,.net 版本的例子提供,而并沒有python,或django的例子。所以就只能自己造輪子了。富文本編輯器,只是個JS框架,與后臺基本沒有關系。后臺只是響應 HTTP 請求,做出處理,并返回結果就好。所以用DJANGO來處理,應該也很容易,開工吧。
下載百度ueditor?
這個就不必多說了,地球人都知道,百度一下就知道了。要注意的是,我下載的是 java utf-8 版本的,因為沒有 django 版本的,所以你隨便下載一個適合自己的 完整版本就可以了。
做一個html模板頁面,在 head 部分,包含以下內容(路徑要改成適合你自己的):
?程序代碼
<script type="text/javascript" charset="utf-8">
????????window.UEDITOR_HOME_URL = "/static/js/ueditor/";
????</script>?
????<script type="text/javascript" charset="utf-8" src="/static/js/ueditor/editor_config.js"></script>
????<script type="text/javascript" charset="utf-8" src="/static/js/ueditor/editor_all_min.js"></script>
????<link rel="stylesheet" type="text/css" href="/static/js/ueditor/themes/default/ueditor.css"/>????
模板的正文可以是如下內容,在<body>與</body>之間:
?程序代碼
<textarea id="content" name="content" style="width:575px;line-height:18px;"></textarea>?
在html模板的結尾,在</body>之前,加上如下代碼:
?程序代碼
<script>
????var ue=new UE.ui.Editor();
????ue.render('content');
</script>
到此,模板配置完畢。在django 工程的 urls.py 文件中配置一個url 路徑,訪問該模板頁面,現在可以看到編輯器加載成功:
這是,點擊上傳圖片圖標,可以看到可以用本地上傳,選擇多個圖片,但卻無法上傳,原因很簡單,沒有后臺響應。所以需要些django后臺來處理。
新建一個 app, 比如 Ueditor,看我的工程結構:
在里面建立一個 views.py 文件,代碼如下:
?程序代碼
#coding:utf-8
'''
Created on 2012-8-29
@author: yihaomen.com
'''
from XieYin import settings
from django.http import HttpResponse, HttpResponseRedirect
from django.views.decorators.csrf import csrf_exempt
import Image
import os
import time
import urllib2
import uuid
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")
????????if not os.path.exists(settings.MEDIA_ROOT[0] + subfolder):
????????????os.makedirs(settings.MEDIA_ROOT[0] + 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 = settings.MEDIA_ROOT[0] + 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 = '/static/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):
????""" 涂鴉文件,處理 """
????pass
到目前為止,剛接觸ueditor ,時間有限,我就做了上傳文件和圖片的。涂鴉,抓遠程圖片等,我在有時間的時候會補充出來。
在urls.py 中配置
?程序代碼
url(r'^ueditor_imgup$','XieYin.app.Ueditor.views.ueditor_ImgUp'),
url(r'^ueditor_fileup$','XieYin.app.Ueditor.views.ueditor_FileUp'),?
修改百度ueditor 配置文件:editor_config.js
?程序代碼
//,imageUrl:URL+"jsp/imageUp.jsp"??
??,imageUrl:"/ueditor_imgup"
??//圖片上傳提交地址
,imagePath:""??????
//附件上傳配置區
,fileUrl:"/ueditor_fileup"?????????????? //附件上傳提交地址
,filePath:""?????????????
啟動django程序
進入剛才的頁面,選擇上傳圖片.
到此,圖片上傳成功,其實文件也一樣,只不過類型不同而已。
注意
MEDIA_ROOT = os.path.join(os.path.dirname(__file__),'static/upload/').replace('\\','/'),
這是我的配置,你可以改成適合你的配置。
今天又抽了一個小時,參考了下java 的代碼,將上面的四個功能也實現,有需要的朋友可以參考. 同樣在前面文章的基礎上,在views.py 里面添加代碼:
在線涂鴉
?程序代碼
@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")
????????if not os.path.exists(settings.MEDIA_ROOT[0] + subfolder):
????????????os.makedirs(settings.MEDIA_ROOT[0] + subfolder)
????????file_name = str(uuid.uuid1())
????????path = str(subfolder + '/' + file_name + '.' + 'png')
????????phisypath = settings.MEDIA_ROOT[0] + path????????
????????f=open(phisypath,'wb+')
????????f.write(base64.decodestring(base64Data))
????????f.close()
????????response=HttpResponse()
????????response.write("{'url':'%s',state:'%s'}" % ('/static/upload/' + subfolder + '/' + file_name + '.' + 'png','SUCCESS'));
????????return response
圖片的在線管理,瀏覽(目錄遞歸瀏覽)?
?程序代碼
def listdir(path,filelist):
????""" 遞歸 得到所有圖片文件信息 """
????phisypath = settings.MEDIA_ROOT[0]
????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,'/static/upload/').replace("//","/"))
@csrf_exempt
def ueditor_imageManager(request):
????""" 圖片在線管理??"""
????filelist=[]
????phisypath = settings.MEDIA_ROOT[0]
????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")????
????if not os.path.exists(settings.MEDIA_ROOT[0] + subfolder):
????????os.makedirs(settings.MEDIA_ROOT[0] + 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 = settings.MEDIA_ROOT[0] + path
????????????piccontent= urllib2.urlopen(url).read()
????????????picfile=open(phisypath,'wb')
????????????picfile.write(piccontent)
????????????picfile.close()
????????????outlist.append('/static/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
更新 urls.py?
?程序代碼
????url(r'^ueditor_imgup$','MyNet.app.Ueditor.views.ueditor_ImgUp'),
????url(r'^ueditor_fileup$','MyNet.app.Ueditor.views.ueditor_FileUp'),
????url(r'^ueditor_getRemoteImage$','MyNet.app.Ueditor.views.ueditor_getRemoteImage'),
????url(r'^ueditor_scrawlUp$','MyNet.app.Ueditor.views.ueditor_ScrawUp'),
????url(r'^ueditor_getMovie$','MyNet.app.Ueditor.views.ueditor_getMovie'),
????url(r'^ueditor_imageManager$','MyNet.app.Ueditor.views.ueditor_imageManager'),
更改ueditor config 配置文件
?程序代碼
????????,imageUrl:"/ueditor_imgup"
????????,imagePath:""??
????????//涂鴉圖片配置區
????????,scrawlUrl:"/ueditor_scrawlUp"?
????????,scrawlPath:""?
????????//附件上傳配置區
????????,fileUrl:"/ueditor_fileup"?
????????,filePath:""??
???????? //遠程抓取配置區
????????,catcherUrl:"/ueditor_getRemoteImage"?
????????,catcherPath:""??
????????//圖片在線管理配置區
????????,imageManagerUrl:"/ueditor_imageManager"?
????????,imageManagerPath:""????
????????//屏幕截圖配置區
????????,snapscreenHost: '127.0.0.1'
????????,snapscreenServerUrl: "/ueditor_imgup"?
????????,snapscreenPath: ""
????????
????????//word轉存配置區
???????
????????,wordImageUrl:"/ueditor_imgup"
????????,wordImagePath:""?
??????
????????//獲取視頻數據的地址
????????,getMovieUrl:"/ueditor_getMovie"?
到此為止,這兩篇文章將所有需要集成的都集成了。
在使用ueditor 之前,我集成過 fckeditor , ckeditor 。基本沒什么難度。但功能沒有ueditor 強大。因此產生了用django 集成 ueditor 的想法。
查看了百度官方的文檔以及例子,發現只有 java,php,.net 版本的例子提供,而并沒有python,或django的例子。所以就只能自己造輪子了。富文本編輯器,只是個JS框架,與后臺基本沒有關系。后臺只是響應 HTTP 請求,做出處理,并返回結果就好。所以用DJANGO來處理,應該也很容易,開工吧。
下載百度ueditor?
這個就不必多說了,地球人都知道,百度一下就知道了。要注意的是,我下載的是 java utf-8 版本的,因為沒有 django 版本的,所以你隨便下載一個適合自己的 完整版本就可以了。
做一個html模板頁面,在 head 部分,包含以下內容(路徑要改成適合你自己的):
?程序代碼
<script type="text/javascript" charset="utf-8">
????????window.UEDITOR_HOME_URL = "/static/js/ueditor/";
????</script>?
????<script type="text/javascript" charset="utf-8" src="/static/js/ueditor/editor_config.js"></script>
????<script type="text/javascript" charset="utf-8" src="/static/js/ueditor/editor_all_min.js"></script>
????<link rel="stylesheet" type="text/css" href="/static/js/ueditor/themes/default/ueditor.css"/>????
模板的正文可以是如下內容,在<body>與</body>之間:
?程序代碼
<textarea id="content" name="content" style="width:575px;line-height:18px;"></textarea>?
在html模板的結尾,在</body>之前,加上如下代碼:
?程序代碼
<script>
????var ue=new UE.ui.Editor();
????ue.render('content');
</script>
到此,模板配置完畢。在django 工程的 urls.py 文件中配置一個url 路徑,訪問該模板頁面,現在可以看到編輯器加載成功:
這是,點擊上傳圖片圖標,可以看到可以用本地上傳,選擇多個圖片,但卻無法上傳,原因很簡單,沒有后臺響應。所以需要些django后臺來處理。
新建一個 app, 比如 Ueditor,看我的工程結構:
在里面建立一個 views.py 文件,代碼如下:
?程序代碼
#coding:utf-8
'''
Created on 2012-8-29
@author: yihaomen.com
'''
from XieYin import settings
from django.http import HttpResponse, HttpResponseRedirect
from django.views.decorators.csrf import csrf_exempt
import Image
import os
import time
import urllib2
import uuid
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")
????????if not os.path.exists(settings.MEDIA_ROOT[0] + subfolder):
????????????os.makedirs(settings.MEDIA_ROOT[0] + 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 = settings.MEDIA_ROOT[0] + 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 = '/static/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):
????""" 涂鴉文件,處理 """
????pass
到目前為止,剛接觸ueditor ,時間有限,我就做了上傳文件和圖片的。涂鴉,抓遠程圖片等,我在有時間的時候會補充出來。
在urls.py 中配置
?程序代碼
url(r'^ueditor_imgup$','XieYin.app.Ueditor.views.ueditor_ImgUp'),
url(r'^ueditor_fileup$','XieYin.app.Ueditor.views.ueditor_FileUp'),?
修改百度ueditor 配置文件:editor_config.js
?程序代碼
//,imageUrl:URL+"jsp/imageUp.jsp"??
??,imageUrl:"/ueditor_imgup"
??//圖片上傳提交地址
,imagePath:""??????
//附件上傳配置區
,fileUrl:"/ueditor_fileup"?????????????? //附件上傳提交地址
,filePath:""?????????????
啟動django程序
進入剛才的頁面,選擇上傳圖片.
到此,圖片上傳成功,其實文件也一樣,只不過類型不同而已。
注意
程序確實實現了上傳于ueditor 的繼承。但還沒有考慮到安全性,比如session的檢查等。需要的,可以自己加上。
上一篇文章提到django與百度ueditor 結合實現文件上傳,圖片上傳。但還有如下功能沒實現:
1. 在線涂鴉后,圖片的保存,并顯示
2. 圖片的在線管理,瀏覽(目錄遞歸瀏覽)
3. 在線視頻搜索
4. 遠程抓圖
在看測試代碼之前,請注意在django程序的settings.py 中配置:
MEDIA_ROOT = os.path.join(os.path.dirname(__file__),'static/upload/').replace('\\','/'),
這是我的配置,你可以改成適合你的配置。
今天又抽了一個小時,參考了下java 的代碼,將上面的四個功能也實現,有需要的朋友可以參考. 同樣在前面文章的基礎上,在views.py 里面添加代碼:
在線涂鴉
?程序代碼
@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")
????????if not os.path.exists(settings.MEDIA_ROOT[0] + subfolder):
????????????os.makedirs(settings.MEDIA_ROOT[0] + subfolder)
????????file_name = str(uuid.uuid1())
????????path = str(subfolder + '/' + file_name + '.' + 'png')
????????phisypath = settings.MEDIA_ROOT[0] + path????????
????????f=open(phisypath,'wb+')
????????f.write(base64.decodestring(base64Data))
????????f.close()
????????response=HttpResponse()
????????response.write("{'url':'%s',state:'%s'}" % ('/static/upload/' + subfolder + '/' + file_name + '.' + 'png','SUCCESS'));
????????return response
圖片的在線管理,瀏覽(目錄遞歸瀏覽)?
?程序代碼
def listdir(path,filelist):
????""" 遞歸 得到所有圖片文件信息 """
????phisypath = settings.MEDIA_ROOT[0]
????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,'/static/upload/').replace("//","/"))
@csrf_exempt
def ueditor_imageManager(request):
????""" 圖片在線管理??"""
????filelist=[]
????phisypath = settings.MEDIA_ROOT[0]
????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")????
????if not os.path.exists(settings.MEDIA_ROOT[0] + subfolder):
????????os.makedirs(settings.MEDIA_ROOT[0] + 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 = settings.MEDIA_ROOT[0] + path
????????????piccontent= urllib2.urlopen(url).read()
????????????picfile=open(phisypath,'wb')
????????????picfile.write(piccontent)
????????????picfile.close()
????????????outlist.append('/static/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
更新 urls.py?
?程序代碼
????url(r'^ueditor_imgup$','MyNet.app.Ueditor.views.ueditor_ImgUp'),
????url(r'^ueditor_fileup$','MyNet.app.Ueditor.views.ueditor_FileUp'),
????url(r'^ueditor_getRemoteImage$','MyNet.app.Ueditor.views.ueditor_getRemoteImage'),
????url(r'^ueditor_scrawlUp$','MyNet.app.Ueditor.views.ueditor_ScrawUp'),
????url(r'^ueditor_getMovie$','MyNet.app.Ueditor.views.ueditor_getMovie'),
????url(r'^ueditor_imageManager$','MyNet.app.Ueditor.views.ueditor_imageManager'),
更改ueditor config 配置文件
?程序代碼
????????,imageUrl:"/ueditor_imgup"
????????,imagePath:""??
????????//涂鴉圖片配置區
????????,scrawlUrl:"/ueditor_scrawlUp"?
????????,scrawlPath:""?
????????//附件上傳配置區
????????,fileUrl:"/ueditor_fileup"?
????????,filePath:""??
???????? //遠程抓取配置區
????????,catcherUrl:"/ueditor_getRemoteImage"?
????????,catcherPath:""??
????????//圖片在線管理配置區
????????,imageManagerUrl:"/ueditor_imageManager"?
????????,imageManagerPath:""????
????????//屏幕截圖配置區
????????,snapscreenHost: '127.0.0.1'
????????,snapscreenServerUrl: "/ueditor_imgup"?
????????,snapscreenPath: ""
????????
????????//word轉存配置區
???????
????????,wordImageUrl:"/ueditor_imgup"
????????,wordImagePath:""?
??????
????????//獲取視頻數據的地址
????????,getMovieUrl:"/ueditor_getMovie"?
到此為止,這兩篇文章將所有需要集成的都集成了。
總結
以上是生活随笔為你收集整理的django 与 百度 ueditor 富文本编辑器集成的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Django的是如何工作的
- 下一篇: Django1.6 用Form实现注册登