当我在终端上使用curl执行以下命令时
curl -X POST http://myuser:mypassword@myweb.com:8000/call/make-call/ -d "tutor=1&billed=1"
我得到以下错误
AssertionError at /call/make-call/ Expected a
Response
,HttpResponse
orHttpStreamingResponse
to be returned from the view, but received a<type 'NoneType'>
我的观点.py是
@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)
我的serializer.py是
class startCallSerializer(serializers.ModelSerializer):
class Meta:
model = call
fields = ('tutor', 'billed', 'rate', 'opentok_sessionid')
我的url.py是
urlpatterns = patterns(
'api.views',
url(r'^call/make-call/$','startCall', name='startCall'),
)
如果
request.method == 'POST'
测试失败,则函数不返回响应。 (应GET请求)只需添加
如果在应用程序开发中没有生成错误代码。
我的完整代码:
相关问题 更多 >
编程相关推荐