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

时间:2018-05-28 07:36:38

标签: python json django request

JSON data和Python request.params的对接:

http://localhost:8000/api/physicalservertask/list_for_home_workpanel/?has_physicalserver=false

正如您所看到的,我在has_physicalserver中添加了url param,这应该是合乎逻辑的' true',logical' 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 ''

enter image description here

1 个答案:

答案 0 :(得分:0)

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

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