0

I currently have a template that loops through a list of URLS, like so.

        {% for i in images %}
        <div class="col">
            <p><a href="{{i}}"><img height="200" src="{{i}}"/></a></p>
            <p><a href="{{i}}">{{i|cut:"/uploads/"|truncatechars:20}}</a></p>
        </div>
        {% endfor %}

The issue is at the time of rendering some of the images are not done processing. So how would I check if the image is available via the url?

nadermx
  • 2,596
  • 7
  • 31
  • 66
  • What do you mean by "not done processing"? The best way is to not include them in the `images` list in the first place. – Selcuk Apr 07 '21 at 05:35
  • Be that as it may, that does not help the issue at hand. As in essence I'm trying to have the template that the image was processed in the allotted time, or not, during a batch process. – nadermx Apr 07 '21 at 05:40
  • 2
    That's what I suggested. You should check the result(s) of the batch process in your view and only include images that are ready in your `images` variable. Templates are not for extended logic such as this, and they are processed right after views anyway, so there will only be milliseconds of difference. – Selcuk Apr 07 '21 at 05:42
  • I don't see how telling me not to do it how I want to do it helps me though. As there is a reason I am asking to do it this specific way, and trying to limit the context of the reason. – nadermx Apr 07 '21 at 05:49
  • You didn't say that you have to do it that way, or explain _why_. That makes your question an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem): _"The XY problem is asking about your attempted solution rather than your actual problem."_ – Selcuk Apr 07 '21 at 05:58

1 Answers1

1

You'd have to make a custom tag or filter that evaluated the availability and sanity of the data. Perhaps using requests & pillow's .verify().

For a static "solution" you can provide a CSS fallback to your HTML img.

Jan Kyu Peblik
  • 1,435
  • 14
  • 20
  • After reading this comment, I made a custom filter using https://stackoverflow.com/questions/18364547/django-custom-filter-to-check-if-file-exists#18364584 – nadermx Apr 07 '21 at 06:30