使用循环不会在烧瓶上显示图像

时间:2019-06-17 12:48:55

标签: python image flask jinja2 url-for

我正在尝试显示一些已上传到烧瓶的图像。我正在使用包含图像名称和一些有关图像的信息的字典,并将其循环到模板中,但是在加载页面时,图像不会显示,图像scr看起来像这样:

img scr="/upload?filename=test_chili2.jpg"

其他工作图像呈现为:

img src="/static/account-icon.png"

这是我模板上当前的代码:

{% for value in image_dictionary %}
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
   <img scr="{{url_for('upload', filename = image_dictionary[loop.index][0])}}">
   <div class = "carousel-caption">
      <h4 style="color:black;">
        Plant: {{image_dictionary[loop.index][1]}}
      </h4>

      <p style="color:black;">
        Prediction Accuracy {{image_dictionary[loop.index][2]}}
      </p>
   </div>  
</div>
{% endfor %}

我正在使用的字典看起来像这样:

{'image': [
  {'picture': 'test_chili2.jpg', 'count': "'green-chili:': 8", 'prediction': '100.0'},
  {'picture': 'test_chili1.jpg', 'count': "'green-chili:': 1", 'prediction': '99.9981164932251'},
  {'picture': 'test_chili.jpg', 'count': "'green-chili:': 3", 'prediction': '97.3533034324646'},
  {'picture': 'test_chili3.jpg', 'count': "'green-chili:': 6", 'prediction': '99.99994039535522'}
 ] }
 {'1': ['test_chili2.jpg', "'green-chili:': 8", '100.0'],
  '2': ['test_chili1.jpg', "'green-chili:': 1", '99.9981164932251'],
  '3': ['test_chili.jpg', "'green-chili:': 3", '97.3533034324646'],
  '4': ['test_chili3.jpg', "'green-chili:': 6", '99.99994039535522']}

1 个答案:

答案 0 :(得分:0)

您的模板中有错字,这是固定版本:

{% for value in image_dictionary %}
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
   <img src="{{url_for('upload', filename = image_dictionary[loop.index][0])}}">
   <div class = "carousel-caption">
      <h4 style="color:black;">
        Plant: {{image_dictionary[loop.index][1]}}
      </h4>

      <p style="color:black;">
        Prediction Accuracy {{image_dictionary[loop.index][2]}}
      </p>
   </div>  
</div>
{% endfor %}

请仔细检查我的更正内容“ src”的第3行,而不是“ scr”。