Serve a dynamically generated image with Django

前端 未结 4 1154
[愿得一人]
[愿得一人] 2020-12-01 04:03

How do I serve a dynamically generated image in Django?

I have an html tag


...
    
...
&         


        
4条回答
  •  隐瞒了意图╮
    2020-12-01 04:15

    I assume you're using PIL (Python Imaging Library). You need to replace your last line with (for example, if you want to serve a PNG image):

    response = HttpResponse(mimetype="image/png")
    img.save(response, "PNG")
    return response
    

    See here for more information.

提交回复
热议问题