Django中的破碎图像

Django中的破碎图像,django,django-rest-framework,Django,Django Rest Framework,我的图像有问题,这是从我在view.p(API)中更改了部分代码开始的 发件人: 致: 我这样做是因为我想把“username”传递给它,我不知道如何使用APIView,所以我使用了这个,但是我的图像被破坏了,我注意到使用APIView,图像url从“127.0.0.1/8000/…”开始,但是在这个新视图中,url是“localhost/…”,我认为这是问题所在 我该怎么做呢?请将请求传递给后序列化程序的上下文 例如: serializer = PostSerializer(queryset,

我的图像有问题,这是从我在view.p(API)中更改了部分代码开始的

发件人:

致:

我这样做是因为我想把“username”传递给它,我不知道如何使用APIView,所以我使用了这个,但是我的图像被破坏了,我注意到使用APIView,图像url从“127.0.0.1/8000/…”开始,但是在这个新视图中,url是“localhost/…”,我认为这是问题所在


我该怎么做呢?请将
请求
传递给
后序列化程序的上下文

例如:

serializer = PostSerializer(queryset, many=True, context = {'request':request})
@api_view(['GET'])
def PostListView(request, *args, **kwargs):
    queryset = Post.objects.all()
    username = request.GET.get('username')
    if username != None:
        queryset = queryset.filter(author__username__iexact=username)
    serializer = PostSerializer(queryset, many=True)
    return Response(serializer.data, status=200)
serializer = PostSerializer(queryset, many=True, context = {'request':request})