Reputation: 879
When i check "datetime.today().date()
" in my views.py
i get yesterday's date.
But when I check the date from linux system with "date
" command i get today's date. I think Django is not updating current date. I have to get current date in the view to make some comparisons, also to print into the view.
I am using Python 2.7 and Django 1.9.
def assistant_page(request, assistant=None):
notes = AssistantNotes.objects.filter(notedate=datetime.today().date()).order_by("time")
file_write(datetime.today().date())
if request.method == 'GET':
return render(request, "assistant_page.html", {'generalnotes': notes})
Upvotes: 0
Views: 154
Reputation: 11
Django uses it's own timezone. you can set it in your settings.py:
TIME_ZONE = 'Europe/london'
this change your whole project timezone. Another way is to use pytz lib. every datetime object has method astimezone. you can convert datetime object to another timezone easily by:
d = datetime.now()
d.astimezone(pytz.timezone('Europe/london'))
Upvotes: 0
Reputation: 2357
Change your Time_Zone
setting to your location specific-
As you said yours is Europe/london. Therefore add this setting in your
settings.py
TIME_ZONE = 'Europe/london'
Upvotes: 2