I have the following problem:
For now I have a working static bootstrap carousel with 3 images. The main idea is to add an app which allows to change these images via the website admin panel. Now I have:
model.py
class BGImagesModel(models.Model):
image1 = models.ImageField(upload_to='images/%Y/%m/%d')
image2 = models.ImageField(upload_to='images/%Y/%m/%d')
image3 = models.ImageField(upload_to='images/%Y/%m/%d')
admin.py
class BGImagesAdmin(admin.ModelAdmin):
list_display = ['image1', 'image2', 'image3']
admin.site.register(BGImagesModel, BGImagesAdmin)
url.py
urlpatterns = [
url(r"^$", "bg_images.views.images", name="images"),
]
views.py
def images(request):
context = {'context_images': BGImagesModel.objects.all()}
return render(request, 'index.html', context)
.html file is the following one. There are 3 main divs' for the images: the first one, where I tried to add an image via admin panel, just doesn't produce any image. The result is - empty. The second one and the third one (where images are hard-coded) do their job perfectly.
index.html
<div class="carousel-inner">
<!-- The first background image via admin panel-->
<div class="active item one">
{% for image in context_images %}
<div class="fill">
<div>
<img src="{{ image.image1.url }}" />
</div>
</div>
{% endfor %}
</div>
<!-- The second background image using inline CSS -->
<div class="item two">
<div class="fill" style="background-image:url({% static 'img/2nd.jpg' %});"></div>
</div>
<!-- The third background image using inline CSS -->
<div class="item three">
<div class="fill" style="background-image:url({% static 'img/3rd.jpg' %});"></div>
</div>
</div>
I've tried to find answer in the internet looking for the similar topics but didn't manage to do this.
One more time about the problem issue: having a try to add an image to the bootstrap carousel via website admin panel fails. An empty slide appears.
I would be really thankful for your help!
UPDATE
If I change my index.html like:
<!-- The first background image via admin panel-->
<div class="active item one">
<div class="fill">
<div>
<img src="{{ context_images.image1.url }}" />
</div>
</div>
</div>
then I get an empty page as well BUT with an icon of broken image in the upper-left part of the window. Using Firebug gives the following:
<div>
<img src="">
</div>
There is no queryset in the <img src="">
. What the reason may it be?