将用pillow处理后的图片,直接生成内容返回到网页

我们可以用 Django 直接把生成的内容返回到网页,以下是操作过程:
from django.utils.six import BytesIO
#视图层代码
def home(request):
image=Image.open(r'D:\webtest\untitled1\app01\aaa.png')
buf=BytesIO()
image.save(buf,'png')
image_stream=buf.getvalue()
#print(image_stream,type(image_stream))
return HttpResponse(image_stream, content_type="image/png")

猜你喜欢

转载自www.cnblogs.com/zhujincheng/p/9989138.html
今日推荐