python-django ckeditor

修改ckeditor 的config.js 文件,添加上传图片功能:
    //config.width = 800;
    //config.height = 400;
    // Simplify the dialog windows.
    config.removeDialogTabs = 'image:advanced;link:advanced';
    var path = window.location;
    var url = path.pathname;
    config.filebrowserImageUploadUrl = url;


html文件,使用class类添加样式:
                          <div class="col-sm-12">
                            <textarea class = "ckeditor" name="sec_bug_detail" rows="10" cols="80">
                                <p>
                                {% autoescape off %}
                                        {{ sec_bug_detail }}
                                {% endautoescape %}
                                </p>
                            </textarea>
                          </div>

也可以使用:
CKEDITOR.replace('sec_bug_detail');

获取ckeditor的文本内容:
formdata["sec_bug_detail"] = CKEDITOR.instances.sec_bug_detail.getData();


django代码:
      if request.method == 'POST':
            #图片上传功能代码                                  
            callback = request.GET.get('CKEditorFuncNum') 
            if callback:
                try:  
                    path = "static/upload/" + time.strftime("%Y%m%d%H%M%S",time.localtime())  
                    f = request.FILES["upload"]  
                    file_name = path + "_" + f.name  
                    des_origin_f = open(file_name, "wb+")    
                    for chunk in f.chunks():  
                        des_origin_f.write(chunk)  
                    des_origin_f.close()  
                except Exception, e:  
                    raise Http404()
                    
                res = "<script>window.parent.CKEDITOR.tools.callFunction("+callback+",'/"+file_name+"', '');</script>"  
                return HttpResponse(res)  

            #漏洞信息修改代码
            if obj == "edit" and sec_bug_id != "" :
                data = {}
                result = bug_report_edit(data)
                return JsonResponse(result)
        
        return render_to_response("bug_edit.html",data)



最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容