#StackBounty: #django #datetime django Localdate doesn't return correct date

Bounty: 50

I am running a django where i have some sort of conditions written based on the date.

My views.py file

from django.utils import timezone

def my_method(current_date=timezone.localdate()):
    logger.info(f"Current date is obtained as {current_date}")

Whenever i load the page, my views.py internally calls this method and the date doesn’t gets updated daily.

In settings.py

TIME_ZONE = 'PST8PDT'
USE_TZ = True

Irrespective of today’s date, it always prints old dates and after few days the date gets updated to correct date and the same date gets continued for next 4-5 days.

What is that i am doing wrong here ?
P.S. I have also tried using python’s native datetime.date.today() which resulted in same abnormal behavior.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.