python base64基本使用

 

1 后端python生成base64 

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 前端进行渲染

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

  

posted @ 2021-03-29 17:01  睁yan-ii  阅读(923)  评论(0)    收藏  举报