Answer the question
In order to leave comments, you need to log in
Django, how to pass a list of numbers in a GET request and validate their serializers.ListField?
Hello!
I want to send a list of numbers to the view with a GET request, validate this list with a serializer, but something goes wrong, I don’t understand in what format to transfer the list to GET, this kind {'panels': [1,2,3]}
does not work, since it perceives the list as a string "[1,2,3 ]". And throws an error
{'panels': {0: [ErrorDetail(string='Требуется целочисленное значение.', code='invalid')]}}
If I pass a number, {'panels': 1}
then everything is ok, but I need to transfer the list.class PanelsSerializer(rest_serializers.Serializer):
panels = rest_serializers.ListField(
required=True,
allow_empty=False,
allow_null=False,
child=rest_serializers.IntegerField()
)
class Panels(APIView):
def get(self, request, **kwargs):
ps = PanelsSerializer(data=request.GET)
ps.is_valid()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question