django time problem

2017-10-05  本文已影响0人  AtrributeError

all time in django are timezone-sensitive(AKA. offeset-aware)
so if you compare a django time with datetime.now()(offset_naive)
if will give u the error as
Can't subtract offset-naive and offset-aware datetimes

So:
The correct solution is to add the timezone info e.g., to get the current time as an aware datetime object in Python 3:

from datetime import datetime, timezone

now = datetime.now(timezone.utc)

上一篇 下一篇

猜你喜欢

热点阅读