I am using the python-requests library to fulfill my requests.
On the website’s homepage, I get a bunch of images and show them to the user. Sometimes these images are deleted and I get a broken image url.
So, I want to check if images exist.
Here is what I did:
items = Item.objects.filter(shop__is_hidden=False, is_hidden=False).order_by("?")[:16]
existing_items = []
for item in items:
response = requests.head(item.item_low_url)
if response.status_code == 200:
existing_items.append(item)
But it will take a little longer than I want.
Is there a faster way?
source
share