settings.py的Django無法從UTC格式更改時區
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Calcutta'
USE_I18N = True
USE_L10N = True
USE_TZ = True
models.py
class Mymodel(models.Model):
auto_increment_id = models.AutoField(primary_key=True)
datetime = models.DateTimeField(auto_now_add=True, blank=True)
ip_add = models.CharField(max_length=30)
data = models.TextField()
我想提出一個POST請求我的網址,這通過我的視圖將數據存儲到數據庫(使用sqlite)。日期時間字段總是以UTC格式存儲時間(這是settings.py中TIME_ZONE變量的默認設置)
我已將TIME_ZONE更改爲'Asia/Calcutta;之後引用此鏈接:https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
但仍然datetime正在以UTC格式存儲。在Google搜索這個問題後,我嘗試將USE_TZ更改爲False,但這對我無效。
我只是在python shell中查詢db中的數據。即
x = Mymodel()
for i in range(len(x)):
print x[i].__dict__
請告知如何將時區更改爲'Asia/Calcutta'。
你在Windows上運行你的Django服務器?如果是這樣,你的Windows時區設置爲「亞洲/加爾各答」? –
在mac上運行。 – Ayush