美文网首页
Django HttpResponse 图片

Django HttpResponse 图片

作者: 孤泉冷月 | 来源:发表于2020-04-25 17:18 被阅读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>

相关文章

网友评论

      本文标题:Django HttpResponse 图片

      本文链接:https://www.haomeiwen.com/subject/cipkwhtx.html