Python 3.x 如何将多个值传递给django rest api url中的一个参数以进行响应?

Python 3.x 如何将多个值传递给django rest api url中的一个参数以进行响应?,python-3.x,django-rest-framework,Python 3.x,Django Rest Framework,我们已经为GET响应创建了一个django restapi,因为这个url如下 127.0.0.1:8000/候选/api/smarttest?软件包\u id=1和章节\u id=1和级别\u类型=easy 在上面的url中,我们只为这些参数传递一个id,但我们希望将多个id传递给一个参数,即章_id=[1,2,3],就像我们希望传递的那样 对于这个我们怎么能通过,这是我的代码 我已尝试使用此代码 def get(self,request): try: # import

我们已经为GET响应创建了一个django restapi,因为这个url如下 127.0.0.1:8000/候选/api/smarttest?软件包\u id=1和章节\u id=1和级别\u类型=easy

在上面的url中,我们只为这些参数传递一个id,但我们希望将多个id传递给一个参数,即章_id=[1,2,3],就像我们希望传递的那样

对于这个我们怎么能通过,这是我的代码

我已尝试使用此代码

def get(self,request):
    try:
        # import pdb;pdb.set_trace()
        response_dict={"status":True,"data":{}}
        package_id = request.GET['package_id']
        chapter_id = request.GET['chapter_id']
        level_type= request.GET.get('complex_id', '0')

        complexity_dict = {
            'easy': [1,2,3,4,5],
            'medium': [6,7,8,9,10]
        }

        question_set = QuestionSet.objects.filter(
            pkg_id__pk=package_id, chapter__pk=chapter_id
        )

        ibs_object = IbsTable.objects.filter(
            ibs_question_setmap__set_id__in=question_set,                           
            complexity__in=complexity_dict.get(level_type,range(0,11))
        )

        v_pks = [qq.pk for qq in ibs_object]
        data = SetContentDetails().splitting(request,v_pks)

        response_dict['data'] = data

    except Exception as e:
        ieonline_except_logger.critical(
            'candidate_management \t index \t '
            + str(e) 
            + '\n'
            + str(traceback.format_exc())
        )
        response_dict = {"status": False, "msg": Exception}
    return Response(response_dict)

要获取具有请求键的数据列表,请使用QueryDict.getlistkey,default=None查看

您的代码将类似于:

chapter_id = request.GET.getlist('chapter_id') # [1,2,3]
然后,在url中传递章节id列表

http://127.0.0.1:8000/candidate/api/smarttest?chapter_id=1&chapter_id=2&chapter_id=3