I'm implementing an API using Django Rest framework. I wonder Python can send POST params as an array like Ruby does?
For example:
POST /api/end_point/
params = { 'user_id': [1,2,3] }
# In controller, we get an array of user_id:
user_ids = params[:user_id] # [1,2,3]
There are a number of ways to deal with this in
django-rest-framework
, depending on what you are actually trying to do.If you are planning on passing this data through
POST
data then you should use aSerializer
. Using a serializer anddjango-rest-framework
sSerializer
you can provide thePOST
data throughjson
or through aform
.Serializer
documentation: http://www.django-rest-framework.org/api-guide/serializers/Serializer Field
documentation: http://www.django-rest-framework.org/api-guide/fields/Specifically you will want to look at the
ListField
.It's not tested, but you will want something along the lines of: