Как отобразить многомерный ответ API в Django?
Я новичок в Django и пытаюсь изучить этот фреймворк. Я пытаюсь отобразить отдельные данные из ответа API. В моем views.py я передаю порядок в контексте.
order = response.json()['order']
return render(request, 'orders.html', {'order': order})
Мне нужно отобразить дату_выполнения и статус_выполнения
Вот теги, которые я пробовал на своем фронтенде.
{{ order.order_date }} работает
{{ order.fulfillments }} также работает
Но они не работают.
{{ order.fulfillments.fulfillment_date }}
{{ order.fulfillments[0].fulfillment_date }}
{{ order.fulfillments[0][0] }}
{{ order.fulfillments.['fulfillment_date'] }}
Спасибо!
API ответ:
"order": {
"order_date": "2022-01-09T00:00:00",
"order_name": null,
"checkout_token": null,
"payment_method": null,
"total_price": null,
"subtotal_price": null,
"currency": null,
"landing_site_url": null,
"source": "orders_api_v3",
"payment_status": null,
"cancellation": null,
"customer": {
"external_id": "111222",
"first_name": "First Name",
"last_name": "Last Name",
"email": "newnew@newnew.com",
"phone_number": null,
"accepts_email_marketing": null,
"accepts_sms_marketing": null,
"custom_properties": null
},
"billing_address": null,
"shipping_address": null,
"custom_properties": null,
"fulfillments": [
{
"fulfillment_date": "2022-01-09T00:00:00",
"status": "success",
"shipment_info": {
"shipment_status": null,
"tracking_company": null,
"tracking_url": null,
"tracking_number": null
},
"fulfilled_items": [
{
"external_product_id": "223553388",
"quantity": 1
}
],
"external_id": "112121212"
}
],
"line_items": [
{
"id": 5554786884,
"created_at": "2022-01-10T03:59:28",
"updated_at": "2022-01-10T03:59:28",
"quantity": 1,
"total_price": null,
"subtotal_price": null,
"coupon_code": null,
"custom_properties": null,
"product_id": 303170668,
"external_product_id": "223553388"
}
],
"id": 2824686328,
"created_at": "2022-01-10T03:59:28",
"updated_at": "2022-01-10T03:59:28",
"store_id": "1111",
"external_id": "112121212"
}
}```
В шаблоне мы не используем [0] для получения первого значения списка, а используем .0.
{{ order.fulfillments.0.fulfillment_date }}