#index.html
{% load static %}
...
<main>
{% for art in carousel %}
<img src="{% static art.image %}" />
{% endfor %}
</main>
#views.py
from gallery.models import Art
def home(request):
carousel = Art.objects.order_by("?")[:5]
context = {
'carousel': carousel,
}
return render(request, 'home/index.html', context)
#gallery.models.py
def upload_gallery_image(instance, filename):
return f"gallery/gallery/img/{instance.title}/{filename}"
class Art(models.Model):
title = models.CharField(max_length=100, unique=True)
image = models.ImageField(upload_to=upload_gallery_image)
short_description = models.CharField(max_length=100)
description = models.TextField()
for_sale = models.BooleanField()
created_on = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
this same setup worked on another site, but refuses to work on this new site I’m building. The only difference here is where the images are being uploaded (and I’ve tried multiple setups for that), and I’m fetching 5 random images instead of specific images (I’ve tried specific images in different locations, and still 404). I’m at a loss.