Can't compare naive and aware datetime.now() <= challenge.datetime_end

后端 未结 9 1289
离开以前
离开以前 2020-12-02 07:58

I am trying to compare the current date and time with dates and times specified in models using comparison operators:

if challenge.datetime_start <= datet         


        
9条回答
  •  天命终不由人
    2020-12-02 08:43

    datetime.datetime.now is not timezone aware.

    Django comes with a helper for this, which requires pytz

    from django.utils import timezone
    now = timezone.now()
    

    You should be able to compare now to challenge.datetime_start

提交回复
热议问题