[英]RuntimeError: OrderedDict mutated during iteration (Python3)
[英]Django rest framework and python3.5 OrderedDict mutated during iteration
我使用Django rest框架和python3.5。 早些时候,我有另一个版本的python,一切运行正常。 当我想从服务器获取带有URL的信息时,例如:
我收到错误:
“ OrderedDict在迭代过程中发生了变异”
。
在views.py中,我有:
from django.shortcuts import render
from companies.models import Companies
from companies.serializers import CompaniesSerializer
from rest_framework import generics
from rest_framework.response import Response
from rest_framework.renderers import JSONRenderer
from rest_framework import status
class CompaniesList(generics.ListCreateAPIView):
queryset = Companies.objects.all()
serializer_class = CompaniesSerializer
class CompaniesDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Companies.objects.all()
serializer_class = CompaniesSerializer
我应该怎么做才能使其正常工作? 哪里有什么改变该命令?
我不知道为什么使用ListCreateApiView突变字典,但我将类更改为类似的功能:
@api_view(['GET'])
def CompaniesList(request):
if request.method == 'GET':
companies = Companies.objects.all()
serializer = CompaniesSerializer(companies, many=True)
return Response(serializer.data)
现在正在运作...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.