将用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")
相关文章
相关标签/搜索