I am wanting to integrate images from Django in the Bootstrap Carousel and the images don't even come out directly. I attach the html code:
<div class="carousel-inner">
{% for img in testimonios %}
<div class="carousel-item
{% if forloop.first %}
active
{% endif %}
">
<img class="d-block w-100" src="{{ img.imagen.url }}" alt="">
</div>
{% endfor %}
</div>
views:
class HomeView(ListView):
"""All home view."""
template_name = 'home.html'
models = Testimonio
context_object_name = 'testimonios'
ordering = ('-created')
def get_queryset(self):
"""Return all rutines."""
return Testimonio.objects.all()
models: class Testimonial(models.Model): """Testimonial model."""
title = models.CharField('Titulo', max_length=150)
imagen = models.ImageField(upload_to='testimonio/images/')
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
def __str__(self):
"""Return title."""
return self.title
The mistake was not including static and media in the urls.
The code to put is the following:
After the ] urlpatterns, you also have to import: