0👍
When you call list() on a queryset in Django, it creates a Python list object containing the same data as the queryset. However, the queryset itself is still lazily evaluated – that is, the database query has not yet been executed.
This means that if you use list() to convert a queryset containing ImageField objects to a Python list in your view, the ImageField instances in the queryset will not be resolved to their corresponding URLs. This is because the URLs are only generated when the queryset is evaluated, which doesn’t happen until later.
To ensure that the ImageField instances are resolved to their corresponding URLs, you need to avoid using list() and instead pass the queryset directly to the template context. This way, the queryset will be evaluated when it is accessed in the template, allowing the ImageField instances to be resolved to their corresponding URLs.
Try the following in your views.py:
@login_required
def list_of_deals_from_setting(request):
business_owner = BusinessOwner.objects.get(user=request.user)
deals = Deal.objects.filter(business_id=business_owner.business.id)
context = {"deals": deals, "number_of_items": deals.values().count()}
return render(request, "deals/deals_list.html", context=context)
1👍
in your template, image source misses a %
it’s:
"{% static ‘img/grey_rectangle.webp’ }"
should be:
"{% static ‘img/grey_rectangle.webp’ %}"
in case that doesn’t work either try changing image src to:
src="{{ MEDIA_URL }}img/grey_rectangle.webp"