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?

5
  • What do you mean by "not done processing"? The best way is to not include them in the images list in the first place. Commented Apr 7, 2021 at 5: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. Commented Apr 7, 2021 at 5: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. Commented Apr 7, 2021 at 5: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. Commented Apr 7, 2021 at 5:49
  • You didn't say that you have to do it that way, or explain why. That makes your question an XY problem: "The XY problem is asking about your attempted solution rather than your actual problem." Commented Apr 7, 2021 at 5:58

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

After reading this comment, I made a custom filter using stackoverflow.com/questions/18364547/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.