title: DjangoRestFramework - Where do I raise a 404 error when `get_queryset()` cannot get an object because it does not exist?
body: <p>This is my view:</p>
  
  <pre><code>class PostListByUsername(generics.ListAPIView):
      serializer_class = PostSerializer
      permission_classes = (IsAuthenticated, IsLikeOrOwnerDeleteOrReadOnly, IsFromSameLocation,)
  
      def get_queryset(self):
          username = self.kwargs['username']
          user = User.objects.get(username=username)
          return Post.objects.filter(owner__username=username).order_by('-createdAt')
  </code></pre>
  
  <p>This is my <code>IsFromSameLocation</code> permission:</p>
  
  <pre><code>class IsFromSameLocation(permissions.BasePermission):
      """
      Permission.
      Allow permissions to authenticated users from the same
      location as the user.
      """
      message = 'Not from the same location.'
  
      def has_permission(self, request, view):
          username = view.kwargs.get('username', None)
          try:
              userProfile = User.objects.get(username=username)
          except:
              return False
  
          return request.user.userextended.location == userProfile.userextended.location
  </code></pre>
  
  <p>With that said, in my <code>get_queryset()</code> method, I do <code>user = User.objects.get(username=username)</code> but if the user does not exist, I want to raise a 404 error. I know that <code>get_queryset()</code> is supposed to return a queryset, so I'm guessing I shouldn't raise a 404 in that method. So where exactly should I do the check to see if the user exists or not? Note that in my permission, I do do a try and except to see if the user exists, but permissions should only return True or False from my understanding (not raise 404 errors).</p>