我有一个非常基本的 GET 方法,该方法应该根据 id 和 comp 来从表中获取令牌字段,如下所示
class merge(APIView):
def get(self, request):
id = request.GET.get('id')
comp = request.GET.get('comp')
queryset = tablename.objects.filter(id=id, comp=comp)
token_instance = queryset.first()
if token_instance:
acnt_token = token_instance.token
serializer = AcToknSerializers(queryset, many=True)
return acnt_token, serializer.data
else:
return None, []
序列化器类
class AcToknSerializers(serializers.ModelSerializer):
class Meta:
model = tablename
fields = ['token']
以下是我在浏览器中调用的方式
http://127.0.0.1:8000/api/syncall/0aabf5ee/75v20375n02
我遇到以下错误
RecursionError at http://127.0.0.1:8000/api/comp-info/syncall/0aabf5ee/75v20375n02
maximum recursion depth exceeded while calling a Python object
Request Method: GET
Request URL: http://127.0.0.1:8000/api/comp-info/syncall/0aabf5ee/75v20375n02
Django Version: 5.0.1
Exception Type: RecursionError
Exception Value:
maximum recursion depth exceeded while calling a Python object
Exception Location: C:\Users\AmiteshSahay\AppData\Local\Programs\Python\Python310\lib\logging\__init__.py, line 424, in usesTime
我该如何解决这个问题?请推荐
class Merge(APIView):
def get(self, request, *args, **kwargs):
rest of your code....!
Pascal Case 用于类,也称为驼峰式命名法,是定义类的最佳实践。