`嗨,我无法在视图函数中仅检索media_data。请查看以下数据:
"data": {
"id": "63f4625a1393d5ff8037a249",
"group_name": "Favorites",
"slug": "favorites",
"parent_id": null,
"updated_at": null,
"media_data": {
"totalAssets": 2,
"media": [
{
"id": "63f849271393d5ff8037a2e5",
"group_id": "63f4625a1393d5ff8037a249",
"content_type": "videos",
"created_at": "2023-02-24T05:20:39.461000"
},
{
"id": "640abd2e1393d5ff8037a3cf",
"group_id": "63f4625a1393d5ff8037a249",
"content_type": "videos",
"created_at": "2023-03-10T05:16:30.210000"
}
]
}
},
"status": true
}
下面是我的view函数:
def fav_view(request):
context={}
context= data
context['title'] = 'Favourite data
return render(request, 'admin/favourite_data.html',context)
当我打印数据时,我得到了整个数据,但我只想有media_data。请协助
2条答案
按热度按时间r7xajy2e1#
我认为
return render(request, 'admin/favourite_data.html',context)['media_data']
应该工作。nlejzf6q2#
假设您有数据dict或响应作为
那么你的上下文应该是:
并在html中访问