When i do the following command over Terminal using curl
curl -X POST http://myuser:[email protected]:8000/call/make-call/ -d "tutor=1&billed=1"
I get the following error
AssertionError at /call/make-call/ Expected a
Response
,HttpResponse
orHttpStreamingResponse
to be returned from the view, but received a<type 'NoneType'>
My views.py is
@api_view(['GET', 'POST'])
def startCall(request):
if request.method == 'POST':
serializer = startCallSerializer(data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
my serializer.py is
class startCallSerializer(serializers.ModelSerializer):
class Meta:
model = call
fields = ('tutor', 'billed', 'rate', 'opentok_sessionid')
my urls.py is
urlpatterns = patterns(
'api.views',
url(r'^call/make-call/$','startCall', name='startCall'),
)
The function does not return a Response
object on "GET" request. That is if request.method == 'POST'
branch check does not pass.
@api_view(['GET', 'POST'])
def startCall(request):
if request.method == 'POST':
serializer = startCallSerializer(data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
#Return this if request method is not POST
return Response({'key': 'value'}, status=status.HTTP_200_OK)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With