将用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")

posted on 2018-11-20 15:19  程序员小朱  阅读(443)  评论(0编辑  收藏  举报

导航