2
我想連接多個字典來返回我的函數。python聯盟字典
def get_params(request, active_id):
tab_parameters = [
shadow(active_id),
light_parameter(active_id)
]
parameters = {
'id': active_id,
'parameters': tab_parameters
}
return response.HttpResponse(json.dumps(parameters), 'application/json')
def light_parameter(active_id):
active_lights = LightParameter.objects.filter(id=active_id).all()
list_parameters = []
for active_light in active_lights:
list_parameters.append({
'name': 'light',
'color': active_light.color,
})
return list_parameters
預期的結果是:
{
"id": 1,
"parameters": [
{
"name": "shadow"
},
{
"color": 1,
"name": "light"
},
{
"color": 2,
"name": "light"
}
}
我的實際效果(用[]):
{
"id": 1,
"parameters": [
{
"name": "shadow"
},
[
{
"color": 1,
"name": "light"
},
{
"color": 2,
"name": "light"
}
]
}
任何想法?我已經嘗試過使用union,update,concatenation但沒有成功。
謝謝!
太棒了!非常感謝 :) – Chaoxys