本帖最后由 nvideo 于 2021-12-1 16:44 编辑
我抛砖引玉一下:- @csrf_exempt
- def upload_image(request, dir_name):
- ##################
- # kindeditor图片上传返回数据格式说明:
- # {"error": 1, "message": "出错信息"}
- # {"error": 0, "url": "图片地址"}
- ##################
- result = {"error": 1, "message": "上传出错"}
- files = request.FILES.get("imgFile", None)
- if files:
- result =image_upload(files, dir_name)
- return HttpResponse(json.dumps(result), content_type="application/json")
复制代码 @csrf_exempt是做什么用的,其实就是Django的CSRF认证
Django内置了很多中间件,其中之一就是CSRF中间件MIDDLEWARE_CLASSES = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware'
|
|