我已经为列表创建了一个API,并使用django rest框架进行了创建。但是它没有在Web可浏览api中打印任何内容。我没有什么问题。当我打印queryset
和serializer
变量时,它给出正确的输出为QuerySet
。为什么会这样?
Views.py
from rest_framework.response import Response
from rest_framework import generics
from .serializers import MovieSerializer
from movie.models import Movie
from rest_framework.permissions import IsAuthenticated
class MovieList(generics.ListCreateAPIView):
queryset = Movie.objects.all()[:10]
serializer_class = MovieSerializer
permission_classes = (IsAuthenticated,)
def list(self, request):
# Note the use of `get_queryset()` instead of `self.queryset`
queryset = self.get_queryset()
# print(queryset)
serializer = MovieSerializer(queryset, many=True)
# print(serializer.data)
return Response(serializer.data)
Serializers.py
from rest_framework import serializers
from movie.models import Movie
class MovieSerializer(serializers.Serializer):
class Meta:
model = Movie
fields = [
'popularity',
'director',
'genre',
'imdb_score',
'name',
]
答案 0 :(得分:2)
问题出在您的
const response = await axios.get(
"http://host.docker.internal:9222/json/version",
{
headers: { Host: "127.0.0.1:9222" }
}
);
const browserWSEndpoint = response.data.webSocketDebuggerUrl.replace(
/127.0.0.1/g,
"host.docker.internal"
);
const browser = await puppeteer.connect({ browserWSEndpoint });
中。您必须使用serializers.py
而不是ModelSerializer
。
Serializer