[Django]-Get list of all custom users in template (Django)

2👍

try with the below view function

class UsersView(TemplateView):
    template_name = 'customer/users/users.html'

    def get_context_data(self,**kwargs):
        context = super(UsersView,self).get_context_data(**kwargs)
        context['object_list'] = CustomUser.objects.all()
        return context

0👍

I don’t understand how this code could ever have worked. Your view is a simple template view, and never does anything to get a list of users: that applies as much to the default User model as to your custom one.

You need to subclass ListView instead of TemplateView, and set the model attribute to your User class.

Leave a comment