如何在html页面上保存图像,以便在刷新页面时不应删除它

时间:2017-11-16 11:54:05

标签: python python-3.x

我想要保存在数据库上的图片应该出现在html页面上的用户个人资料中。刷新页面时不应删除它。

views.py

def userpic(request):
if request.method =="POST":
    user= request.user.id
    image = json.loads(request.body)['new_image'][0].split(',')[1]
    imgdata = base64.b64decode(image)
    filename = 'static/images/image.png'  # I assume you have a way of picking unique filenames
    with open(filename, 'wb') as f:
        f.write(imgdata)
        print os.path.abspath(filename)
    attend = attendence.objects.create(user_id=user,user_pic=filename)
    attend.save()

    return HttpResponse('success')

0 个答案:

没有答案