我是靠谱客的博主 辛勤咖啡豆,这篇文章主要介绍django拖拽图片到编辑器完成上传,并返回图片路径,现在分享给大家,希望可以做个参考。

    '''拖拽图片到编辑器完成上传,并返回图片路径'''
    # 上传图片根路径
    PicBaseRoot = "static/Image/"
    file_img = request.FILES.getlist('file')  # 获取文件对象列表
    # 自定义名称
    for i in file_img:
        image = models.Image()
        random_name = str(int(random.random()*10000000000000000))
        PicPath = PicBaseRoot + random_name + ".jpg"
        image.ImageName = random_name + ".jpg"
        image.save()
        with open(PicPath, 'wb') as pic:
            for c in i.chunks():
                pic.write(c)
        try:
            message = {'path': PicPath, "status": True}
            image.save()  # 保存数据
            return JsonResponse(message)
        except Exception as e:
            print(e)
            return JsonResponse({"status": False})

最后

以上就是辛勤咖啡豆最近收集整理的关于django拖拽图片到编辑器完成上传,并返回图片路径的全部内容,更多相关django拖拽图片到编辑器完成上传内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部