[Solved]-Django – how to get user logged in (get_queryset in ListView)


Your question is completely unrelated to the traceback. The traceback shows that you have an invalid character (in position 748) in the template used by your view. Remove it.

The view itself looks ok. The correct way to get the user in the method is self.request.user, as you are already doing.

You could simplify the method slightly – you don’t need to do the pagination in the method, the ListView will take care of that for you.

class UserLocationsListView(ListView):
    paginate_by = 10

    def get_queryset(self):
        queryset = super(UserLocationsListView, self).get_queryset()
        queryset = queryset.filter(user=self.request.user)
        return queryset

Leave a comment