In Django API, you can pass multiple values of the same parameter in two common ways:

  1. Using comma-separated values (CSV):

If you want to pass multiple values of the same parameter in a single query parameter, you can use comma-separated values (CSV). For example, if you want to pass multiple IDs to retrieve their details, you can pass them as ID=1,2,3. In your API view, you can retrieve these values as a list using the split() method as shown below:

id_list = request.GET.get('ID').split(',')
  1. Using multiple query parameters with the same name:

Another way to pass multiple values of the same parameter is to use multiple query parameters with the same name. For example, if you want to pass multiple filter values for a search query, you can pass them as filter=value1&filter=value2&filter=value3. In your API view, you can retrieve these values as a list using the getlist() method as shown below:

filter_list = request.GET.getlist('filter')
``
how to pass multiple value of same param in djago api

原文地址: https://www.cveoy.top/t/topic/ecyl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录