一、下载

http://kindeditor.net/down.php

删除asp、asp.net、php、jsp、examples文件夹

拷贝到static目录下

二、配置

kindeditor目录下新建conifg.js

KindEditor.ready(function(K) {
K.create('#id_content', {
width: '800px',
height: '500px',
uploadJson:'/upload_image',
});
//http://kindeditor.net/docs/option.html
});

admin.py

class NoticeAdmin(admin.ModelAdmin):
class Media:
js = [
'/static/plugins/kindeditor/kindeditor-all-min.js',
'/static/plugins/kindeditor/lang/zh-CN.js',
'/static/plugins/kindeditor/config.js'
]
admin.site.register(Notice, NoticeAdmin)

views.py

from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def upload_image(request):
allow_suffix = ['jpg', 'png', 'jpeg', 'gif', 'bmp']
files = request.FILES.get("imgFile", None)
if files:
file_suffix = files.name.split(".")[-1]
if file_suffix not in allow_suffix:
return JsonResponse({"error": 1, "message": "图片格式不正确"})
file_name = str(uuid.uuid1()) + "." + file_suffix
file_path = os.path.join(settings.MEDIA_ROOT, 'image', file_name)
url_path = os.path.join(settings.MEDIA_URL, 'image', file_name)
print file_path
with open(file_path, 'wb') as f:
f.write(files.file.read())
return JsonResponse({"error": 0, "url": url_path})

settings.py

MEDIA_URL = "/upload/"
MEDIA_ROOT = os.path.join(BASE_DIR, "upload")

urls.py

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

最新文章

  1. YOURPHP的分页完整版
  2. yii2的GridView和ActiveDataProvider具体使用
  3. PostgreSQL没有redo log multiplexing
  4. 《javascript权威指南》第9章 例9-8源码
  5. loadrunner参数化总结
  6. CodeIgniter入门——HelloWorld
  7. android项目--上下文菜单
  8. php curl调用相关api
  9. Dom 简介
  10. SpringMVC简单入门
  11. 使用异步方法在XAML中绑定系统时间
  12. Android 平台 Native 代码的崩溃捕获机制及实现
  13. shell 基础(二)变量
  14. JavaScript 环境和作用域
  15. [SF] Symfony 标准 HttpFoundation\Request 实现分析
  16. Centos 7.x nginx隐藏版本号
  17. MySQL Json类型的数据处理
  18. 学习笔记(2)——实验室集群LVS配置
  19. HDU 4502 吉哥系列故事——临时工计划(一维动态规划)
  20. $#65279导致页面body会出现一个空白行

热门文章

  1. css解决fixed布局不会出现滚动条问题
  2. Spark + sbt + IDEA + HelloWorld + MacOS
  3. CRLF——http response 拆分攻击(webgoat)
  4. go module配置
  5. CentOS 7.5在线安装Docker 18.09.3
  6. 【leetcode算法-简单】14. 最长公共前缀
  7. Oracle表级约束和列级约束
  8. Chrome浏览器控制台报 POST http://*** net::ERR_BLOCKED_BY_CLIENT
  9. 码云以及Git的使用
  10. GAN——ModeCollapse