Reputation:
I am trying to create a face detection program that will detect a face and log the time it was detected in. I created a Django template and am trying to display the time on the template. But the time it is displaying is wrong.
To double check, I tried printing the current time separately in a different python program. That displays the time correctly.
This is code for displaying the time in the Django template (info.html)
views.py
import datetime
def detect(request):
global now
now = datetime.datetime.now()
def info(request):
return render(request, 'info.html', {'entry_time':now})
this is code I used in the separate python file
import datetime
print(datetime.datetime.now())
both the code is the same. I checked online and found this links How to get the current time in Python
I also tried setting the timezone to my timezone (Asia/Kolkata) according to this link Is there a list of Pytz Timezones?
I feel that I am not declaring the 'now' variable in the right place. Please help me out. I am new to Django
Thanks in advance
Upvotes: 0
Views: 401
Reputation: 2591
In your settings.py change TIME_ZONE variable as you like.
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = True
Upvotes: 1