Issue
I am new in Django and I am trying to learn this framework. I am trying to display the individual data from an API response. From my views.py, I am passing order in a context.
order = response.json()['order']
return render(request, 'orders.html', {'order': order})
I need to display fulfillment_date and fulfillment_status
These are the tags I have tried on my frontend.
{{ order.order_date }}
is working
{{ order.fulfillments }}
is also working
But these are not working.
{{ order.fulfillments.fulfillment_date }}
{{ order.fulfillments[0].fulfillment_date }}
{{ order.fulfillments[0][0] }}
{{ order.fulfillments.['fulfillment_date'] }}
Thanks!
API response:
"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": "[email protected]",
"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"
}
}```
Solution
In template we don't use [0]
to get first value of list, use .0
.
{{ order.fulfillments.0.fulfillment_date }}
Answered By - NixonSparrow
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.