![](/img/trans.png)
[英]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.