上传图片到Djang的cloudinary

2024-06-20 15:17:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将单个图像从HTML发送到django视图, 使用ajax,把图片上传到cloudinary! 它总是把我扔到编码错误下面!不知道是什么! 有人真的能帮上忙吗!**在

代码:

<input type="file" name="live" id="live-upload" /> 
var dataimg = new FormData();
dataimg.append('img', $('#live-upload')[0].files[0]);
$.ajax({
    url: '/event/creatives/',
    type: 'POST',
    processData: false, // important 
    contentType: false, // important 
    dataType: 'json',
    data: dataimg
});


import cloudinary
import cloudinary.uploader
import cloudinary.api

cloudinary.config(
  cloud_name="name",
  api_key="key",
  api_secret="secret")

@login_required
def update_creatives(request):
    try:
        cloudinary_response = cloudinary.uploader.upload(request.FILES['img'])
    except Exception as e:
        print str(e)

错误:

^{pr2}$

Tags: nameimportapilivefalseimgtype错误