Skip to content

problem with many=True and multipart/form-data #1308

@hihello1123

Description

@hihello1123

views.py

import json
from rest_framework.response import Response
from rest_framework.views import APIView
from drf_spectacular.utils import extend_schema
from test_app.serializer import *
class test_answer(APIView):
    @extend_schema(
        request={
            # "application/json": req_Serializer,
            "multipart/form-data": req_Serializer,
        },
        responses={"200": OK_response(), "400": ERROR_response()},
    )
    def post(self, req):
        data_list = req.data.get("list")
        post_list = req.POST.get("list")
        print("data ", data_list)
        print("post ", post_list)
        return Response({"message": "hi"})

serializer.py

from rest_framework import serializers

class item(serializers.Serializer):
    txt = serializers.CharField()

class req_Serializer(serializers.Serializer):
    list = item(many=True)

class OK_response(serializers.Serializer):
    status = serializers.IntegerField(default=200)

class ERROR_response(serializers.Serializer):
    status = serializers.IntegerField(default=400)

with these code i expected 2 item() objects in a list
like below:

list = [
    { "txt":"asdf"},{ "txt","qwer"}
]

But swagger-ui makes below:

'list=[{"txt":"asdf"},"{\n  \"txt\": \"qwer\"\n}"]'

image

how can i make it right?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions