python base64基本使用

 

1 后端python生成base64 

1
2
3
4
5
6
7
8
import os                                         
import base64                                     
                                                    
with open('../static/img/user-icon.jpg','rb') as f:
    data=f.read()                                 
    encodesstr=base64.b64encode(data)  # 转换       
    print(str(encodesstr,'utf-8'))  # 必须指定编码      
                                                   

2 前端进行渲染

1
`<img src="data:image/png;base64,***>`

  

posted @   睁yan-ii  阅读(915)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示