Django HttpResponse 图片

2020-04-25  本文已影响0人  孤泉冷月

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>
上一篇 下一篇

猜你喜欢

热点阅读