Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected a `Response`, `HttpResponse` or `HttpStreamingResponse` to be returned from the view, but received a `<class 'NoneType'>` [duplicate]

models.py

class Wishlist(models.Model):
    home = models.ForeignKey(Home, on_delete=models.CASCADE, blank=False, null=False)
    user = models.ForeignKey(User, on_delete=models.CASCADE, blank=False, null=False)

    def __str__(self):
        return "{} - {}".format(self.user.username, self.home.address)

    class Meta:
        ordering = ('user',)

urls.py

urlpatterns = [
    path(r'wishlist/<int:pk>/', views.WishlistGetUserItems.as_view(), name='wish-user-list'),
]

views.py

class WishlistGetUserItems(APIView):

    def get(self, request, pk):
        wishlist = get_list_or_404(Wishlist, user=pk)
        data = serializers.UserWishlistSerializer(wishlist).data
        Response(data, status=status.HTTP_200_OK)

I've tried also to print message but seems like the method is not called

like image 446
masaterofnothing Avatar asked Jan 04 '19 18:01

masaterofnothing


1 Answers

You should add return before Response.

def get(self, request, pk):
    wishlist = get_list_or_404(Wishlist, user=pk)
    data = serializers.UserWishlistSerializer(wishlist).data
    return Response(data, status=status.HTTP_200_OK)
like image 179
Top Top Avatar answered Nov 07 '22 02:11

Top Top