I am getting a Assertion error in the views of my django project

AssertionError: Expected a Response, HttpResponse or HttpStreamingResponse to be returned from the view, but received a <class 'NoneType'>

Code:-

from rest_framework.decorators import api_view
from user_app.api.serializers import RegistrationSerializer

@api_view(['POST',])
def registration_view(request):
    if request.method == 'POST':
        serializer = RegistrationSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return serializer.data

Before it was showing the error: TypeError: User() got unexpected keyword arguments: 'password2'

Then I removed the password2 field and I again added it, now it is showing an Assertion Error.

Your all code fine just need to return Response like this...

from rest_framework.response import Response

@api_view(['POST',])
def registration_view(request):
    if request.method == 'POST':
        serializer = RegistrationSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response({'data':serializer.data,'message':'Data Created'}, status=status.HTTP_201_CREATED) # need to return Response
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Back to Top