0
votes

I have a field that's part of a larger set of data that's being returned from an api and passed to my template as a dictionary. The field is an iso 8601 formatted date. I would like to reformat this to a different, more readable, format.

I've tried using the built-in filters, both date and from the humanize filter, naturaltime but neither work. I'm pretty sure this is because the field that's being passed as part of the dictionary is coming through as a string rather than a datetime object.

So, is there any way I can change this field to be a datetime object, either in the dictionary or in the template? I thought about creating a custom template filter, would that work or is there a better more elegant way of reformatting this field?

1
You need to show some code, with an example of the data being passed.Daniel Roseman
You can catch it in the view, convert to datetime object and pass reformatted it to the context.schrodigerscatcuriosity

1 Answers

0
votes

I ended up just using a custom filter:

import dateutil.parser import parse

def newdate(value):
    return parse(value)