![](/img/trans.png)
[英]Python web frameworks: HTML server-side templates and duplication of code
[英]Python display a server-side image in a html
我在服務器文件夾中有一個圖像。 在我的處理Get請求的do_GET()函數中,我想將圖像發送回去。 我選擇使用self.wfile.write('')。 誰能告訴我如何將圖像源包含在img標簽中? 還是有更好的方法來做到這一點? 謝謝。
您可以使用數據URI將圖像的“源”包含在img標簽中,如下所示:
<img alt="Embedded Image" src="data:image/png;base64,<your base64 encoding here>" />
使用base64 python標准lib生成base64字符串:
import base64
with open("image.png", "rb") as image:
encoded_string = base64.b64encode(image.read())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.