Python 为什么JSON bool数据作为字符串传递到Django后端?

Python 为什么JSON bool数据作为字符串传递到Django后端?,python,json,django,request,Python,Json,Django,Request,JSON数据和Pythonrequest.params的对接: http://localhost:8000/api/physicalservertask/list_for_home_workpanel/?has_physicalserver=false 如您所见,我在url中添加了has_physicalserver参数,该参数应为逻辑“true”,逻辑“false”,但在Django API中,我将其作为str获得 has_physicalserver_list = query_params

JSON数据
和Python
request.params的对接:

http://localhost:8000/api/physicalservertask/list_for_home_workpanel/?has_physicalserver=false
如您所见,我在
url
中添加了
has_physicalserver
参数,该参数应为逻辑“true”,逻辑“false”,但在Django API中,我将其作为
str
获得

has_physicalserver_list = query_params.pop('has_physicalserver')
has_physicalserver = has_physicalserver_list[0] if (isinstance(has_physicalserver_list, list) and len(has_physicalserver_list) > 0) else ''

查询参数是字符串。您可以使用
json
解析它

import json
has_physicalserver_list = query_params.pop('has_physicalserver') # string true/false
has_physicalserver_list = json.loads(has_physicalserver_list) # True/False

因为它不是JSON,它只是一个查询参数。值总是字符串;如果您想解析它,那么应该显式地进行解析。