Django HttpResponse 图片

django

import os
import base64

# 读取图片
if (os.path.isfile('detect/output/' + time + '.jpg')):
    file = open(u'detect/output/' + time + '.jpg', 'rb')
    result = file.read()


# 对图片的2进制对象进行base64编码
result = base64.b64encode(result)
return HttpResponse(result, content_type='image/jpeg')

HTML

<div id="app">
  <img :src="'data:image/png;base64,' + img_base64">
<div>
<script>
var app = new Vue({
  el: '#app',
  data: {
    img_base64:null,
  },
  mount:{
    axios
        .post("url")
        .then(respose=>{
            this.img_base64 = response.data
         })
        .catch(error=>{
          console.log(error);
        })
  }
})
</script>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容