这是我第一次使用Django并经过很长时间的Python工作。我有类方法,应该使用**kwargs
接受字典但它正在响应"insertToLeadHelper() takes exactly 1 argument (2 given)"
from rest_framework.response import Response
from rest_framework.renderers import JSONRenderer
from rest_framework.parsers import JSONParser
from rest_framework.views import APIView
class test(APIView):
"""
A view that can accept POST requests with JSON content.
"""
parser_classes = (JSONParser,)
renderer_classes = (JSONRenderer, )
def insertToLeadHelper(self, **data):
print data
def post(self, request, format=None):
print "here"
self.insertToLeadHelper(request.data)
return Response({"status" : request.data},status=status.HTTP_200_OK)
请帮忙
答案 0 :(得分:0)
为什么使用**kwargs
语法?您直接传递字典,不想将其分解为kwargs。只需接受数据字典:
def insertToLeadHelper(self, data):