[Fixed]-My Django application is not displaying content from the db

1👍

You have context_object_name = 'all_galleries' in

class IndexView(generic.ListView):
    template_name = 'photos/index.html'
    context_object_name = 'all_galleries'
    ...

However you loop over galleries in template

{% for gallery in galleries %}

Needs to be

{% for gallery in all_galleries %}

Also you have {% if gallery %} before the loop in template which doesn’t make sense, because there is no gallery variable. You need to check {% if all_galleries %}.

NOTE #1: your field names in classes that in models better be lowercase.

NOTE #2: in IndexView you need to provide model and you can remove get_queryset(), because there is no custom query that retrieve data with filters. So you need to use

class IndexView(generic.ListView):
    model = Gallery
    template_name = 'photos/index.html'
    context_object_name = 'all_galleries'

Leave a comment