Skip to content

Python code snippet – How do i check if a django queryset is empty?

queryset = demo.objects.filter(name="non_existent_name")

if queryset.exists():
    serializer = DemoSerializer(queryset, many=True)
    return Response(
    return Response(status=status.HTTP_404_NOT_FOUND)
See also  PHP code snippet - How to call function in blade laravel?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.