Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html jinja和flask中的字典,用于从base64格式检索JPG/PNG图像_Html_Python 3.x_Api_Flask_Jinja2 - Fatal编程技术网

Html jinja和flask中的字典,用于从base64格式检索JPG/PNG图像

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

我想使用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.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)
返回值