Reputation: 1
I have a Django project to keep track of tasks in an office environment. I have this model for tasks, and it has a finish_date
attribute that is assigned as soon as I access the route to do the desired task. I'm trying to use datetime
and pytz
to correctly format the date to the DateTimeField attribute.
Here's the view code:
task.data_conclusao=datetime.now().astimezone(pytz.timezone('America/Sao_Paulo'))
task.save()
It's saving the datetime
but when I render it on the HTML, it just doesn't adjust to the timezone I set. Can anyone help me?
Upvotes: 0
Views: 36
Reputation: 11
to fix the timezone issue on Django application,which ensures Use_Tz = True in settings of the application, and make sure to set your TIME_ZONE, and use the timezone template filter in the HTML to display the datetime in the timezone :
{% load tz %} {{ datatime_variable|timezone:"America/Sao_Paulo" }}
Upvotes: 1