问题
I have an app that uses
import datetime
datetime.datetime.now()
default=datetime.now
auto_now=True
auto_now_add=True
I'm changing the above codes to the below.
from django.utils import timezone
timezone.now() # instead of datetime.datetime.now()
default=timezone.now # instead of datetime.now
auto_now # override save() or pre_save() .. ok don't need this change in recent django.
auto_now_add # override post_save() to set time when `created`.. don't need this change either
Am I missing something or doing something superflous?
I'm using an open source app and it uses a lot of datetime.datetime ..
It's really pain to change all that.. hope there was an easier way.
回答1:
In your settings file you have to set USE_TZ = True. From docs:
Time zone support is disabled by default. To enable it, set USE_TZ = True in your settings file
来源:https://stackoverflow.com/questions/17653369/how-do-i-make-my-site-timezone-aware