[Answered ]-If block not being evaluated in templates

1๐Ÿ‘

โœ…

You need to specify the name of the context object, so:

class EventView(generic.ListView):
    model = Event
    template_name = 'timer/index.html'
    queryset = Event.objects.order_by('-day')[:7]
    context_object_name = 'events'

It does not matter what variable name you use in get_queryset. It is passed to the template as object_list, and as the name specified in the context_object_name attribute [Django-doc]. If you do not specify such attribute, it will use modelname_list.

Leave a comment