Html jinja和flask中的字典,用于从base64格式检索JPG/PNG图像
我想使用flask和jinja模板在HTML页面中显示base64n字符串中的图像Html jinja和flask中的字典,用于从base64格式检索JPG/PNG图像,html,python-3.x,api,flask,jinja2,Html,Python 3.x,Api,Flask,Jinja2,我想使用flask和jinja模板在HTML页面中显示base64n字符串中的图像 image_64 = base64.encodestring(image_read).decode("ascii") output = {"username":username, "email": email, "Base64 Image": image_64} return render_template('display.htm
image_64 = base64.encodestring(image_read).decode("ascii")
output = {"username":username, "email": email, "Base64 Image": image_64}
return render_template('display.html', result = output)
如果键是“Base64 image”,我想将字典值显示为image。否则仅显示值
我尝试的是:
{% for key, value in result.items() %}
<p> {{ key }} </p>
{% if result['Base64 Image'] != "" %}
<img src="data:image/jpg;base64,{{ value }}" alt="my_image" id="img"/> </img><br>
{% else %}
<p> {{ value }} </p><br>
{% endif %}
{% endfor %}
{%用于键,结果中的值。项()%}
{{key}}
{%if结果['Base64 Image']!=“”%}
{%else%}
{{value}}
{%endif%}
{%endfor%}
有一件事,您可以尝试将图像保存在dir中,并以所需格式加载图像
要保存图像,您可以尝试:
@app.route('/api/scaning',methods=['GET'])
def scan_qr():
img=request.files['img']
##保存图像
img.save(“temp_dir/”+img.filename)
##加载图像
img=cv2.imread(f“temp_dir/{img.filename}”)
返回值=MyModel.det\u qr(img)
返回值