【发布时间】:2020-11-23 18:40:33
【问题描述】:
我已经使用 PIL 库编辑了用户个人资料照片,并尝试在我的 django 模板中显示新图像,但不知何故图像没有显示,这是我在 views.py 中的代码:
enterim = Image.open(get_user_model().objects.get(username=request.user).avatar)
width, height = im.size
newsize = (50, 50)
image = im.resize(newsize)
buffer = BytesIO()
image.save(buffer, "PNG")
img_str = buffer.getvalue()
return render(request, '../templates/templates_v2/update_location.html', {'updatelocation_form': updatelocation_form,'user_info':user_info,'img_str':img_str})
这是html模板中的img标签:
<img src='data:image/png;"+ {{img_str}} + "'/>
提前致谢
【问题讨论】: