当前位置: 移动技术网 > IT编程>脚本编程>Python > Django CKEdirtor配置(图片上传,粘贴,文件上传)

Django CKEdirtor配置(图片上传,粘贴,文件上传)

2018年12月20日  | 移动技术网IT编程  | 我要评论

qq超市官方论坛,拉美西斯二世复原图,坐爱电影

注:pycharm django2.0  ckeditor4

一.ckeditor引入

1     1.ckeditor引入(下载的ckeditor包直接粘贴到static内)
2     <script  type="text/javascript" src="/static/ckeditor/ckeditor.js"></script>
3     <script  type="text/javascript" src="/static/ckeditor/config.js"></script>
4     2.下为ckeditor生效的标签(还有另外几种方式就不赘述了)
5     <textarea class="ckeditor" name="editor1" > </textarea>
6     注:如上刷新页面编辑器应该已经生效了

二.

如pycharm在打开的时候报错

eslint:please specify eslint .......

需要安装下 node.js 和 eslint(网上有资料) 并在setting 配置下

三.

1     如果是第一次应用富文本需要设置下media文件用来存放上传数据
2     在setting  文件在下面添加
3         media_root=os.path.join(base_dir,"app01","media")
4         media_url="/media/"
5     在主url添加
6         url('media/(?p<path>.*)', serve, {'document_root': settings.media_root}),

四.
上传函数应用局部禁用csrf
 1 from django.views.decorators.csrf import csrf_exempt 2 在函数上添加@csrf_exempt 

五.
下面需要在ckeditor包下config.js设置

 1 ckeditor.editorconfig = function( config ) {
 2 // define changes to default configuration here. for example:
 3 //config.language = 'zh-cn';//更改为中文
 4 // config.uicolor = '#aadc6e';
 5 config.width = 790.5;
 6 config.height = 400;
 7 config.filebrowserimageuploadurl = '/itbg/bgimg.html/'; // 图片上传路径
 8 config.uploadurl='/itbg/bgimg.html/';
 9 //图片粘贴(上行只是支持编辑器的“图像”上传。这行可以直接桌面拖拽图片和从word复制多张图片到编辑器)
10 config.filebrowseruploadurl='/itbg/bgimg.html/'
11 //附件上传(如需要上传附件如.zip .pdf)会在“插入/编辑超链接”出现“上传”栏(默认是木有的)
12 };
13 注:如发现上面都不生效可以尝试清下浏览器缓存。

六.视图处理

 1     views部分
 2     现在创先在项目目录创建文件如:\media\upload\img
 3     def imgdata(request):
 4     imgfile = request.files.get("upload")#拿到文件对象
 5     img_path = os.path.join(文件路径\media\upload\img',imgfile.name)#拼接生成上传文件的路径
 6     #chunks向上面生成的路径保存数据
 7     with open(img_path,'wb')as f:
 8     for chunk in imgfile.chunks():
 9         f.write(chunk)
10     #回显数据
11     response={
12         "uploaded":1,
13         "filename": imgfile.name,
14         "url": '/media/upload/img/'+imgfile.name
15     }
16     return httpresponse(json.dumps(response))

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网