python - Flask and Jinja for loop skip if file contains errors -


i'm having issue trying display thumbs. problem when run jinja2 variable displays alt text, rather have skip or pass if thumb contains errors instead of displaying alt text.

here code

{% block content %}       {% if games %}         {% g in games if g.game_thumb %}              <img src="static{{ g.game_thumb }}" class="img-rounded" alt="{{ g.game_name }}" width="150" height="150">         {%endfor%}     {% endif %} {% endblock %} 

i ended solving via flask route via.

from pil import image     try:         image.open(thumb).verify()         print "image"     except:         print "failed"         continue 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -