I’m trying to understand how to do this. Initially I thought I could pass the data through the view as context and use that to display the image, but its not working at all. Here is where I’m at currently:
model
class CarouselImage(models.Model):
image = models.ImageField(upload_to='carousel/')
description = models.CharField(max_length=255, blank=True, null=True)
def __str__(self):
return self.description or f"Image {self.id}"
view
class IndexView(generic.TemplateView):
template_name = "mainapp/index.html"
carousel_images = CarouselImage.objects.all()
extra_context={'background_style': 'indexBody',
'carousel_images': carousel_images}
html
<img src="{{ image.image.url }}" class="d-block w-100" alt="{{ image.description }}">