1.引入js
{% load static %}
<script src="{% static 'sadmin/js/jquery-1.12.4.min.js' %}" ></script>
2.修改 tinymce_setup.js
imageupload_url: “/sadmin/upload_file/”
3.配制上传目录
Setting.py 中
#定义上传文件夹的路径
UPLOAD_ROOT = os.path.join(BASE_DIR,‘upload’)
4.在项目url.py中配制
from web.settings import UPLOAD_ROOT
#导入文件路由库
from django.views.static import serve
re_path(’^upload/(?P
5.上传代码
img = request.FILES.get(‘file’)
f = open(os.path.join(settings.UPLOAD_ROOT,’’,img.name),‘wb’)
#写文件 遍历图片文件流
for chunk in img.chunks():
f.write(chunk)
#关闭文件流
f.close()
mes={}
mes['path'] = "/upload/"+img.name
mes[‘error’] = False
return HttpResponse(json.dumps(mes,ensure_ascii=False))