Python Shopify API output formatted datetime string in django template

Shopify API gives a string in ISO 8601 format for the order.created_at field.

For example: 2016-04-10T16:30:09-04:00

I want to format this and show it directly in a template, so I have tried:

{{ order.created_at|date:'Y-m-d H:i' }}

But nothing displays, and I don't get any errors. I think it is because it is a string and not a datetime object. I don't want to convert it first though in my view.


Adding to what @ChidG said in his comment, you need to either:

  1. Do the modification in your view prior to rendering.

  2. Add a custom templatetag that takes this string and does it for you. Ie, {{ order.created_at|shopify_date|date:'Y-m-d H:i' }}

If you really insist on not doing the first, then the second is your only other hope.

js interview questions