簡體   English   中英

在 Flask 中顯示圖像

[英]show image in Flask

我正在嘗試使用此庫從我的 sqlite3 數據庫中渲染圖像:

#!/usr/bin/python3 from flask import Flask, render_template, request, send_file from flask_sqlalchemy import SQLAlchemy from io import BytesIO import base64 @app.route('/show/') def show(): file_data = FileContents.query.filter_by(id=3).first() image = b64encode(file_data.data)
return render_template('display.html', image = image)


並將這個變量放在 html 中:

<html>
<body>
<img src="data:image;base64,{{image}}"/>
</body>
</html>

但是我無法顯示圖像(我正在使用 python3 和 google chorme)有人可以幫助獲取它嗎?

您可以添加擴展名。 示例: <img src="data:image/png;base64,{{ image }}"\\>並將圖片解碼為utf-8 return render_template('display.html', image = image.decode('utf8'))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM