ListView object has no attribute 'object_list'

I have this code:

class UserListView(PermissionRequiredMixin, ListView):
    permission_required = 'account.view_user'
    model = Profile
    template_name = 'dashboard/user_list.html'
    paginate_by = 20
    ordering = '-id'

    def post(self, request, *args, **kwargs):
        if 'delete' in request.POST.getlist('action'):
            selected_ids = request.POST.getlist('user-checkbox')
            User.objects.filter(pk__in=selected_ids).delete()
            messages.success(request, 'Success')
        return render(request, self.template_name, self.get_context_data())

    def get_queryset(self):
        users = self.model.objects.filter(user__is_superuser=False)
        if self.request.method == 'GET' and (q := self.request.GET.get('q')) is not None:
            users = users.filter(
                Q(first_name__icontains=q) |
                Q(last_name__icontains=q) |
                Q(user__username__icontains=q)
            )
        return users

I didn’t change the value of context_object_name and by default it is the same as object_list, but when I send a post request to the page, I get this error
image

In the general case, your “post” should end with a redirect, not just the rendering of a template.

In this specific case, your “post” processing does not create an object_list attribute on the class for the template.

If you’re not familiar with the processing flow of the Django-provided CBVs, you may find both the Classy Class-Based Views site and the CBV diagrams page to be very useful.