图片在线管理页面不显示
其中的在线管理页面图片无法显示,控制台报错500,后台报错内容如下:
Python NameError: name 'unicode' is not defined `
出错的位置位于DjangoUeditor/views.py
,之所以报错是因为Python2 的unicode 函数在 Python3 中被命名为 str。在 Python3 中使用我们需要使用str 来代替 Python2中的 unicode如此页面可以正常显示图片了
添加文件删除action
为了实现ueditor编辑器自定义了在线图片以及在线附件的图片删除以及附件删除功能,需要在原有的DjangoUeditor的后台逻辑上增加文件删除功能,
在/DjangoUeditor/views.py下修改部分内容如下:
- 新增delete_site_file的action
...
@csrf_exempt
def get_ueditor_controller(request):
"""获取ueditor的后端URL地址 """
action = request.GET.get("action", "")
reponseAction = {
"config": get_ueditor_settings,
"uploadimage": UploadFile,
"uploadscrawl": UploadFile,
"uploadvideo": UploadFile,
"uploadfile": UploadFile,
"catchimage": catcher_remote_image,
"listimage": list_files,
"listfile": list_files,
"delete_site_file":delete_site_file,#添加action
}
return reponseAction[action](request)
....
- 新增删除文件的函数
#ueditor新增在线管理文件删除功能
@csrf_exempt
def delete_site_file(request):
path=request.POST.get("path")
file=USettings.BASE_DIR+path
if os.path.isfile(file):
os.remove(file)
return HttpResponse("ok",content_type="text/html")